From 1bdd1ff0d07620074bba1da4f71048dde8198809 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 25 Dec 2024 09:17:06 -0600 Subject: [PATCH] Restyled More work on documentation (#420) * Restyled by fourmolu * Restyled by hlint --------- Co-authored-by: Restyled.io --- src/Disco/Doc.hs | 248 +++++++++++++++--------------- src/Disco/Interactive/Commands.hs | 19 ++- 2 files changed, 133 insertions(+), 134 deletions(-) diff --git a/src/Disco/Doc.hs b/src/Disco/Doc.hs index ce003b00..44047ff2 100644 --- a/src/Disco/Doc.hs +++ b/src/Disco/Doc.hs @@ -7,9 +7,9 @@ -- -- Built-in documentation. module Disco.Doc ( - DocKey(..), - RefType(..), - Reference(..), + DocKey (..), + RefType (..), + Reference (..), mkRef, mkIntro, docMap, @@ -39,7 +39,7 @@ data RefType where deriving (Eq, Ord, Show, Read, Bounded, Enum) -- | A reference for further reading. -data Reference = Reference { refType :: RefType, ref :: String } +data Reference = Reference {refType :: RefType, ref :: String} deriving (Eq, Ord, Show) mkRef :: String -> Reference @@ -54,99 +54,99 @@ mkIntro = Reference Intro docMap :: Map DocKey (String, [Reference]) docMap = M.fromList - [ PrimKey (PrimUOp Neg) ==> - "Arithmetic negation." ==> - [] - , PrimKey (PrimBOp Add) ==> - "The sum of two numbers, types, or graphs." ==> - [mkIntro "arithmetic", mkRef "addition"] - , PrimKey (PrimBOp Sub) ==> - "The difference of two numbers." ==> - [mkIntro "arithmetic", mkRef "subtraction"] - , PrimKey (PrimBOp SSub) ==> - "The difference of two numbers, with a lower bound of 0." ==> - [mkIntro "arithmetic", mkRef "subtraction", mkRef "symbols"] - , PrimKey (PrimBOp Mul) ==> - "The product of two numbers, types, or graphs." ==> - [mkIntro "arithmetic", mkRef "multiplication"] - , PrimKey (PrimBOp Div) ==> - "Divide two numbers." ==> - [mkIntro "arithmetic", mkRef "division"] - , PrimKey (PrimBOp IDiv) ==> - "The integer quotient of two numbers, rounded down." ==> - [mkIntro "arithmetic", mkRef "integerdiv"] - , PrimKey (PrimBOp Mod) ==> - "a mod b is the remainder when a is divided by b." ==> - [mkRef "mod"] - , PrimKey (PrimBOp Exp) ==> - "Exponentiation. a ^ b is a raised to the b power." ==> - [mkIntro "arithmetic", mkRef "exponentiation"] - , PrimKey (PrimUOp Fact) ==> - "n! computes the factorial of n, that is, 1 * 2 * ... * n." ==> - [mkRef "factorial"] - , PrimKey PrimFloor ==> - "floor(x) is the largest integer which is <= x." ==> - [mkIntro "arithmetic", mkRef "round", mkRef "symbols"] - , PrimKey PrimCeil ==> - "ceiling(x) is the smallest integer which is >= x." ==> - [mkIntro "arithmetic", mkRef "round", mkRef "symbols"] - , PrimKey PrimAbs ==> - "abs(x) is the absolute value of x." ==> - [mkIntro "arithmetic", mkRef "abs"] - , PrimKey PrimMin ==> - "min(x,y) is the minimum of x and y, i.e. whichever is smaller." ==> - [mkRef "compare"] - , PrimKey PrimMax ==> - "max(x,y) is the maximum of x and y, i.e. whichever is larger." ==> - [mkRef "compare"] - , PrimKey (PrimUOp Not) ==> - "Logical negation: not(T) = F and not(F) = T." ==> - [mkRef "logic-ops", mkRef "symbols"] - , PrimKey (PrimBOp And) ==> - "Logical conjunction (and): T /\\ T = T; otherwise x /\\ y = F." ==> - [mkRef "logic-ops", mkRef "symbols"] - , PrimKey (PrimBOp Or) ==> - "Logical disjunction (or): F \\/ F = F; otherwise x \\/ y = T." ==> - [mkRef "logic-ops", mkRef "symbols"] - , PrimKey (PrimBOp Impl) ==> - "Logical implication (implies): T -> F = F; otherwise x -> y = T." ==> - [mkRef "logic-ops", mkRef "symbols"] - , PrimKey (PrimBOp Iff) ==> - "Biconditional (if and only if)." ==> - [mkRef "logic-ops", mkRef "symbols"] - , PrimKey (PrimBOp Eq) ==> - "Equality test. x == y is T if x and y are equal." ==> - [mkRef "compare"] - , PrimKey (PrimBOp Neq) ==> - "Inequality test. x /= y is T if x and y are unequal." ==> - [mkRef "compare", mkRef "symbols"] - , PrimKey (PrimBOp Lt) ==> - "Less-than test. x < y is T if x is less than (but not equal to) y." ==> - [mkRef "compare"] - , PrimKey (PrimBOp Gt) ==> - "Greater-than test. x > y is T if x is greater than (but not equal to) y." ==> - [mkRef "compare"] - , PrimKey (PrimBOp Leq) ==> - "Less-than-or-equal test. x <= y is T if x is less than or equal to y." ==> - [mkRef "compare", mkRef "symbols"] - , PrimKey (PrimBOp Geq) ==> - "Greater-than-or-equal test. x >= y is T if x is greater than or equal to y." ==> - [mkRef "compare", mkRef "symbols"] - , PrimKey (PrimBOp CartProd) ==> - "Cartesian product, i.e. the collection of all pairs. Also works on bags and sets." ==> - [mkRef "cp", mkRef "symbols"] - , PrimKey (PrimPower) ==> - "Power set, i.e. the set of all subsets. Also works on bags." ==> - [mkRef "power"] - , PrimKey (PrimBOp Union) ==> - "Union of two sets (or bags)." ==> - [mkRef "set-ops", mkRef "symbols"] - , PrimKey (PrimBOp Inter) ==> - "Intersection of two sets (or bags)." ==> - [mkRef "set-ops", mkRef "symbols"] - , PrimKey (PrimBOp Diff) ==> - "Difference of two sets (or bags)." ==> - [mkRef "set-ops"] + [ PrimKey (PrimUOp Neg) + ==> "Arithmetic negation." + ==> [] + , PrimKey (PrimBOp Add) + ==> "The sum of two numbers, types, or graphs." + ==> [mkIntro "arithmetic", mkRef "addition"] + , PrimKey (PrimBOp Sub) + ==> "The difference of two numbers." + ==> [mkIntro "arithmetic", mkRef "subtraction"] + , PrimKey (PrimBOp SSub) + ==> "The difference of two numbers, with a lower bound of 0." + ==> [mkIntro "arithmetic", mkRef "subtraction", mkRef "symbols"] + , PrimKey (PrimBOp Mul) + ==> "The product of two numbers, types, or graphs." + ==> [mkIntro "arithmetic", mkRef "multiplication"] + , PrimKey (PrimBOp Div) + ==> "Divide two numbers." + ==> [mkIntro "arithmetic", mkRef "division"] + , PrimKey (PrimBOp IDiv) + ==> "The integer quotient of two numbers, rounded down." + ==> [mkIntro "arithmetic", mkRef "integerdiv"] + , PrimKey (PrimBOp Mod) + ==> "a mod b is the remainder when a is divided by b." + ==> [mkRef "mod"] + , PrimKey (PrimBOp Exp) + ==> "Exponentiation. a ^ b is a raised to the b power." + ==> [mkIntro "arithmetic", mkRef "exponentiation"] + , PrimKey (PrimUOp Fact) + ==> "n! computes the factorial of n, that is, 1 * 2 * ... * n." + ==> [mkRef "factorial"] + , PrimKey PrimFloor + ==> "floor(x) is the largest integer which is <= x." + ==> [mkIntro "arithmetic", mkRef "round", mkRef "symbols"] + , PrimKey PrimCeil + ==> "ceiling(x) is the smallest integer which is >= x." + ==> [mkIntro "arithmetic", mkRef "round", mkRef "symbols"] + , PrimKey PrimAbs + ==> "abs(x) is the absolute value of x." + ==> [mkIntro "arithmetic", mkRef "abs"] + , PrimKey PrimMin + ==> "min(x,y) is the minimum of x and y, i.e. whichever is smaller." + ==> [mkRef "compare"] + , PrimKey PrimMax + ==> "max(x,y) is the maximum of x and y, i.e. whichever is larger." + ==> [mkRef "compare"] + , PrimKey (PrimUOp Not) + ==> "Logical negation: not(T) = F and not(F) = T." + ==> [mkRef "logic-ops", mkRef "symbols"] + , PrimKey (PrimBOp And) + ==> "Logical conjunction (and): T /\\ T = T; otherwise x /\\ y = F." + ==> [mkRef "logic-ops", mkRef "symbols"] + , PrimKey (PrimBOp Or) + ==> "Logical disjunction (or): F \\/ F = F; otherwise x \\/ y = T." + ==> [mkRef "logic-ops", mkRef "symbols"] + , PrimKey (PrimBOp Impl) + ==> "Logical implication (implies): T -> F = F; otherwise x -> y = T." + ==> [mkRef "logic-ops", mkRef "symbols"] + , PrimKey (PrimBOp Iff) + ==> "Biconditional (if and only if)." + ==> [mkRef "logic-ops", mkRef "symbols"] + , PrimKey (PrimBOp Eq) + ==> "Equality test. x == y is T if x and y are equal." + ==> [mkRef "compare"] + , PrimKey (PrimBOp Neq) + ==> "Inequality test. x /= y is T if x and y are unequal." + ==> [mkRef "compare", mkRef "symbols"] + , PrimKey (PrimBOp Lt) + ==> "Less-than test. x < y is T if x is less than (but not equal to) y." + ==> [mkRef "compare"] + , PrimKey (PrimBOp Gt) + ==> "Greater-than test. x > y is T if x is greater than (but not equal to) y." + ==> [mkRef "compare"] + , PrimKey (PrimBOp Leq) + ==> "Less-than-or-equal test. x <= y is T if x is less than or equal to y." + ==> [mkRef "compare", mkRef "symbols"] + , PrimKey (PrimBOp Geq) + ==> "Greater-than-or-equal test. x >= y is T if x is greater than or equal to y." + ==> [mkRef "compare", mkRef "symbols"] + , PrimKey (PrimBOp CartProd) + ==> "Cartesian product, i.e. the collection of all pairs. Also works on bags and sets." + ==> [mkRef "cp", mkRef "symbols"] + , PrimKey PrimPower + ==> "Power set, i.e. the set of all subsets. Also works on bags." + ==> [mkRef "power"] + , PrimKey (PrimBOp Union) + ==> "Union of two sets (or bags)." + ==> [mkRef "set-ops", mkRef "symbols"] + , PrimKey (PrimBOp Inter) + ==> "Intersection of two sets (or bags)." + ==> [mkRef "set-ops", mkRef "symbols"] + , PrimKey (PrimBOp Diff) + ==> "Difference of two sets (or bags)." + ==> [mkRef "set-ops"] , OtherKey "N" ==> docN , OtherKey "ℕ" ==> docN , OtherKey "Nat" ==> docN @@ -164,33 +164,33 @@ docMap = , OtherKey "Rational" ==> docQ , OtherKey "Bool" ==> docB , OtherKey "Boolean" ==> docB - , OtherKey "Unit" ==> - "The unit type, i.e. a type with only a single value." ==> - [mkRef "unit", mkRef "symbols"] - , OtherKey "Prop" ==> - "The type of propositions." ==> - [mkRef "prop"] - , OtherKey "List" ==> - "List(T) is the type of lists whose elements have type T." ==> - [mkRef "list", mkRef "list-lib"] - , OtherKey "Bag" ==> - "Bag(T) is the type of bags (i.e. sets with multiplicity) whose elements have type T." ==> - [mkRef "bag", mkRef "symbols"] - , OtherKey "Set" ==> - "Set(T) is the type of finite sets whose elements have type T." ==> - [mkRef "set", mkRef "symbols"] - , OtherKey "|~|" ==> - "Absolute value, or the size of a collection." ==> - [mkIntro "arithmetic", mkRef "size"] - , OtherKey "{?" ==> - "{? ... ?} is a case expression, for choosing a result based on conditions." ==> - [mkRef "case"] - , OtherKey "λ" ==> - "λ (aka lambda, alternatively `\\`) introduces an anonymous function." ==> - [mkRef "anonymous-func", mkRef "symbols"] - , OtherKey "#" ==> - "The # character is used to denote the cardinality of an element in a bag." ==> - [mkRef "bag"] + , OtherKey "Unit" + ==> "The unit type, i.e. a type with only a single value." + ==> [mkRef "unit", mkRef "symbols"] + , OtherKey "Prop" + ==> "The type of propositions." + ==> [mkRef "prop"] + , OtherKey "List" + ==> "List(T) is the type of lists whose elements have type T." + ==> [mkRef "list", mkRef "list-lib"] + , OtherKey "Bag" + ==> "Bag(T) is the type of bags (i.e. sets with multiplicity) whose elements have type T." + ==> [mkRef "bag", mkRef "symbols"] + , OtherKey "Set" + ==> "Set(T) is the type of finite sets whose elements have type T." + ==> [mkRef "set", mkRef "symbols"] + , OtherKey "|~|" + ==> "Absolute value, or the size of a collection." + ==> [mkIntro "arithmetic", mkRef "size"] + , OtherKey "{?" + ==> "{? ... ?} is a case expression, for choosing a result based on conditions." + ==> [mkRef "case"] + , OtherKey "λ" + ==> "λ (aka lambda, alternatively `\\`) introduces an anonymous function." + ==> [mkRef "anonymous-func", mkRef "symbols"] + , OtherKey "#" + ==> "The # character is used to denote the cardinality of an element in a bag." + ==> [mkRef "bag"] ] where docN = ("The type of natural numbers: 0, 1, 2, ...", refsN) diff --git a/src/Disco/Interactive/Commands.hs b/src/Disco/Interactive/Commands.hs index 5e446a8c..98270f81 100644 --- a/src/Disco/Interactive/Commands.hs +++ b/src/Disco/Interactive/Commands.hs @@ -73,7 +73,7 @@ import Disco.Pretty qualified as PP import Disco.Property (prettyTestResult) import Disco.Syntax.Operators import Disco.Syntax.Prims ( - Prim (PrimBOp, PrimUOp, PrimFloor, PrimCeil, PrimAbs), + Prim (PrimAbs, PrimBOp, PrimCeil, PrimFloor, PrimUOp), toPrim, ) import Disco.Typecheck @@ -475,11 +475,11 @@ handleDocPrim prim = do PrimAbs -> describeAlts False False ["abs(x)", "|x|"] _ -> [] ) - ++ ( case prim of - PrimUOp u -> [describePrec (uPrec u)] - PrimBOp b -> [describePrec (bPrec b) <> describeFixity (assoc b)] - _ -> [] - ) + ++ ( case prim of + PrimUOp u -> [describePrec (uPrec u)] + PrimBOp b -> [describePrec (bPrec b) <> describeFixity (assoc b)] + _ -> [] + ) case attrs of [] -> pure () _ -> info . vcat $ attrs @@ -520,10 +520,9 @@ handleDocMap k = case M.lookup k docMap of [ text d , PP.empty ] - ++ - case refs of - [] -> [] - _ -> map formatReference refs ++ [PP.empty] + ++ case refs of + [] -> [] + _ -> map formatReference refs ++ [PP.empty] ------------------------------------------------------------ -- eval