Skip to content

Commit

Permalink
Restyled More work on documentation (#420)
Browse files Browse the repository at this point in the history
* Restyled by fourmolu

* Restyled by hlint

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
github-actions[bot] and restyled-commits authored Dec 25, 2024
1 parent ddd2bd3 commit 1bdd1ff
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 134 deletions.
248 changes: 124 additions & 124 deletions src/Disco/Doc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
--
-- Built-in documentation.
module Disco.Doc (
DocKey(..),
RefType(..),
Reference(..),
DocKey (..),
RefType (..),
Reference (..),
mkRef,
mkIntro,
docMap,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
19 changes: 9 additions & 10 deletions src/Disco/Interactive/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1bdd1ff

Please sign in to comment.