Copyright | disco team and contributors |
---|---|
License | BSD-3-Clause |
Maintainer | byorgey@gmail.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Various pretty-printing facilities for disco.
Synopsis
- module Disco.Pretty.DSL
- class Pretty t where
- withPA :: Member (Reader PA) r => PA -> Sem r (Doc ann) -> Sem r (Doc ann)
- setPA :: Member (Reader PA) r => PA -> Sem r a -> Sem r a
- lt :: Member (Reader PA) r => Sem r (Doc ann) -> Sem r (Doc ann)
- rt :: Member (Reader PA) r => Sem r (Doc ann) -> Sem r (Doc ann)
- mparens :: Member (Reader PA) r => PA -> Sem r (Doc ann) -> Sem r (Doc ann)
- prettyStr :: Pretty t => t -> Sem r String
- pretty' :: Pretty t => t -> Sem r (Doc ann)
- prettyDecimal :: Rational -> String
- findRep :: Ord a => [a] -> ([a], Int)
- findRep' :: Ord a => Map a Int -> Int -> [a] -> ([a], Int)
- digitalExpansion :: Integer -> Integer -> Integer -> ([Integer], Int)
- module Disco.Pretty.Prec
- data Doc ann
Documentation
module Disco.Pretty.DSL
Instances
Pretty Core Source # | |
Pretty Op Source # | |
Pretty Side Source # | |
Pretty Binding Source # | Pretty-print a binding, i.e. a pairing of a name (with optional type annotation) and term. |
Pretty Branch Source # | Pretty-print a single branch in a case expression. |
Pretty Decl Source # | |
Pretty Guard Source # | |
Pretty Pattern Source # | |
Pretty Qual Source # | Pretty-print a single qualifier in a comprehension. |
Pretty Term Source # | |
Pretty ATerm Source # | |
Pretty DiscoError Source # | |
Pretty Defn Source # | |
Pretty ModuleName Source # | |
Pretty BOp Source # | Pretty-print a binary operator, by looking up its concrete syntax
in the |
Pretty TyOp Source # | |
Pretty UOp Source # | Pretty-print a unary operator, by looking up its concrete syntax
in the |
Pretty Constraint Source # | |
Pretty RelMap Source # | |
Pretty SimpleConstraint Source # | |
Pretty TyVarInfo Source # | |
Pretty TyVarInfoMap Source # | |
Pretty Atom Source # | |
Pretty BaseTy Source # | |
Pretty Con Source # | |
Pretty Ilk Source # | |
Pretty PolyType Source # | Pretty-print a polytype. Note that we never explicitly print
|
Pretty Type Source # | |
Pretty UAtom Source # | |
Pretty Qualifier Source # | |
Pretty a => Pretty (Set a) Source # | |
Pretty (Telescope Guard) Source # | Pretty-print the guards in a single branch of a case expression. |
Pretty (Telescope Qual) Source # | Pretty-print the qualifiers in a comprehension. |
Pretty (QName a) Source # | |
Pretty a => Pretty (Substitution a) Source # | |
Pretty a => Pretty (Graph a) Source # | |
Pretty (Name a) Source # | |
Pretty a => Pretty [a] Source # | |
(Pretty k, Pretty v) => Pretty (Map k v) Source # | |
Pretty (Name a, Bind [Pattern] Term) Source # | Pretty-print a single clause in a definition. |
Pretty (String, TyDefBody) Source # | Pretty-print a type definition. |
setPA :: Member (Reader PA) r => PA -> Sem r a -> Sem r a Source #
Locally set the precedence and associativity within a subcomputation.
lt :: Member (Reader PA) r => Sem r (Doc ann) -> Sem r (Doc ann) Source #
Mark a subcomputation as pretty-printing a term on the left of an operator (so parentheses can be inserted appropriately, depending on the associativity).
rt :: Member (Reader PA) r => Sem r (Doc ann) -> Sem r (Doc ann) Source #
Mark a subcomputation as pretty-printing a term on the right of an operator (so parentheses can be inserted appropriately, depending on the associativity).
mparens :: Member (Reader PA) r => PA -> Sem r (Doc ann) -> Sem r (Doc ann) Source #
Optionally surround a pretty-printed term with parentheses,
depending on its precedence and associativity (given as the PA
argument) and that of its context (given by the ambient 'Reader
PA' effect).
prettyDecimal :: Rational -> String Source #
Pretty-print a rational number using its decimal expansion, in
the format nnn.prefix[rep]...
, with any repeating digits enclosed
in square brackets.
digitalExpansion :: Integer -> Integer -> Integer -> ([Integer], Int) Source #
digitalExpansion b n d
takes the numerator and denominator of a
fraction n/d between 0 and 1, and returns a pair of (1) a list of
digits ds
, and (2) a nonnegative integer k such that splitAt k
ds = (prefix, rep)
, where the infinite base-b expansion of
n/d is 0.(prefix ++ cycle rep)
. For example,
digitalExpansion 10 1 4 = ([2,5,0], 2) digitalExpansion 10 1 7 = ([1,4,2,8,5,7], 0) digitalExpansion 10 3 28 = ([1,0,7,1,4,2,8,5], 2) digitalExpansion 2 1 5 = ([0,0,1,1], 0)
It works by performing the standard long division algorithm, and looking for the first time that the remainder repeats.
module Disco.Pretty.Prec
The abstract data type
represents pretty documents that have
been annotated with data of type Doc
annann
.
More specifically, a value of type
represents a non-empty set of
possible layouts of a document. The layout functions select one of these
possibilities, taking into account things like the width of the output
document.Doc
The annotation is an arbitrary piece of data associated with (part of) a document. Annotations may be used by the rendering backends in order to display output differently, such as
- color information (e.g. when rendering to the terminal)
- mouseover text (e.g. when rendering to rich HTML)
- whether to show something or not (to allow simple or detailed versions)
The simplest way to display a Doc
is via the Show
class.
>>>
putStrLn (show (vsep ["hello", "world"]))
hello world