disco-0.1.6: Functional programming language for teaching discrete math.
Copyrightdisco team and contributors
LicenseBSD-3-Clause
Maintainerbyorgey@gmail.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

Disco.Pretty

Description

Various pretty-printing facilities for disco.

Synopsis

Documentation

class Pretty t where Source #

Methods

pretty :: Members '[Reader PA, LFresh] r => t -> Sem r (Doc ann) Source #

Instances

Instances details
Pretty Core Source # 
Instance details

Defined in Disco.AST.Core

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Core -> Sem r (Doc ann) Source #

Pretty Op Source # 
Instance details

Defined in Disco.AST.Core

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Op -> Sem r (Doc ann) Source #

Pretty Side Source # 
Instance details

Defined in Disco.AST.Generic

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Side -> Sem r (Doc ann) Source #

Pretty Binding Source #

Pretty-print a binding, i.e. a pairing of a name (with optional type annotation) and term.

Instance details

Defined in Disco.AST.Surface

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Binding -> Sem r (Doc ann) Source #

Pretty Branch Source #

Pretty-print a single branch in a case expression.

Instance details

Defined in Disco.AST.Surface

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Branch -> Sem r (Doc ann) Source #

Pretty Decl Source # 
Instance details

Defined in Disco.AST.Surface

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Decl -> Sem r (Doc ann) Source #

Pretty Guard Source # 
Instance details

Defined in Disco.AST.Surface

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Guard -> Sem r (Doc ann) Source #

Pretty Pattern Source # 
Instance details

Defined in Disco.AST.Surface

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Pattern -> Sem r (Doc ann) Source #

Pretty Qual Source #

Pretty-print a single qualifier in a comprehension.

Instance details

Defined in Disco.AST.Surface

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Qual -> Sem r (Doc ann) Source #

Pretty Term Source # 
Instance details

Defined in Disco.AST.Surface

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Term -> Sem r (Doc ann) Source #

Pretty ATerm Source # 
Instance details

Defined in Disco.AST.Typed

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => ATerm -> Sem r (Doc ann) Source #

Pretty DiscoError Source # 
Instance details

Defined in Disco.Error

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => DiscoError -> Sem r (Doc ann) Source #

Pretty Defn Source # 
Instance details

Defined in Disco.Module

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Defn -> Sem r (Doc ann) Source #

Pretty ModuleName Source # 
Instance details

Defined in Disco.Names

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => ModuleName -> Sem r (Doc ann) Source #

Pretty BOp Source #

Pretty-print a binary operator, by looking up its concrete syntax in the bopMap.

Instance details

Defined in Disco.Pretty

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => BOp -> Sem r (Doc ann) Source #

Pretty TyOp Source # 
Instance details

Defined in Disco.Pretty

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => TyOp -> Sem r (Doc ann) Source #

Pretty UOp Source #

Pretty-print a unary operator, by looking up its concrete syntax in the uopMap.

Instance details

Defined in Disco.Pretty

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => UOp -> Sem r (Doc ann) Source #

Pretty Constraint Source # 
Instance details

Defined in Disco.Typecheck.Constraints

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Constraint -> Sem r (Doc ann) Source #

Pretty RelMap Source # 
Instance details

Defined in Disco.Typecheck.Solve

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => RelMap -> Sem r (Doc ann) Source #

Pretty SimpleConstraint Source # 
Instance details

Defined in Disco.Typecheck.Solve

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => SimpleConstraint -> Sem r (Doc ann) Source #

Pretty TyVarInfo Source # 
Instance details

Defined in Disco.Typecheck.Solve

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => TyVarInfo -> Sem r (Doc ann) Source #

Pretty TyVarInfoMap Source # 
Instance details

Defined in Disco.Typecheck.Solve

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => TyVarInfoMap -> Sem r (Doc ann) Source #

Pretty Atom Source # 
Instance details

Defined in Disco.Types

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Atom -> Sem r (Doc ann) Source #

Pretty BaseTy Source # 
Instance details

Defined in Disco.Types

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => BaseTy -> Sem r (Doc ann) Source #

Pretty Con Source # 
Instance details

Defined in Disco.Types

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Con -> Sem r (Doc ann) Source #

Pretty Ilk Source # 
Instance details

Defined in Disco.Types

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Ilk -> Sem r (Doc ann) Source #

Pretty PolyType Source #

Pretty-print a polytype. Note that we never explicitly print forall; quantification is implicit, as in Haskell.

Instance details

Defined in Disco.Types

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => PolyType -> Sem r (Doc ann) Source #

Pretty Type Source # 
Instance details

Defined in Disco.Types

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Type -> Sem r (Doc ann) Source #

Pretty UAtom Source # 
Instance details

Defined in Disco.Types

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => UAtom -> Sem r (Doc ann) Source #

Pretty Qualifier Source # 
Instance details

Defined in Disco.Types.Qualifiers

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Qualifier -> Sem r (Doc ann) Source #

Pretty a => Pretty (Set a) Source # 
Instance details

Defined in Disco.Pretty

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Set a -> Sem r (Doc ann) Source #

Pretty (Telescope Guard) Source #

Pretty-print the guards in a single branch of a case expression.

Instance details

Defined in Disco.AST.Surface

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Telescope Guard -> Sem r (Doc ann) Source #

Pretty (Telescope Qual) Source #

Pretty-print the qualifiers in a comprehension.

Instance details

Defined in Disco.AST.Surface

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Telescope Qual -> Sem r (Doc ann) Source #

Pretty (QName a) Source # 
Instance details

Defined in Disco.Names

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => QName a -> Sem r (Doc ann) Source #

Pretty a => Pretty (Substitution a) Source # 
Instance details

Defined in Disco.Subst

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Substitution a -> Sem r (Doc ann) Source #

Pretty a => Pretty (Graph a) Source # 
Instance details

Defined in Disco.Typecheck.Graph

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Graph a -> Sem r (Doc ann) Source #

Pretty (Name a) Source # 
Instance details

Defined in Disco.Pretty

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Name a -> Sem r (Doc ann) Source #

Pretty a => Pretty [a] Source # 
Instance details

Defined in Disco.Pretty

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => [a] -> Sem r (Doc ann) Source #

(Pretty k, Pretty v) => Pretty (Map k v) Source # 
Instance details

Defined in Disco.Pretty

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => Map k v -> Sem r (Doc ann) Source #

Pretty (Name a, Bind [Pattern] Term) Source #

Pretty-print a single clause in a definition.

Instance details

Defined in Disco.AST.Surface

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => (Name a, Bind [Pattern] Term) -> Sem r (Doc ann) Source #

Pretty (String, TyDefBody) Source #

Pretty-print a type definition.

Instance details

Defined in Disco.Types

Methods

pretty :: forall (r :: EffectRow) ann. Members '[Reader PA, LFresh] r => (String, TyDefBody) -> Sem r (Doc ann) Source #

withPA :: Member (Reader PA) r => PA -> Sem r (Doc ann) -> Sem r (Doc ann) Source #

Convenience function combining setPA and mparens, since we often want to simultaneously indicate what the precedence and associativity of a term is, and optionally surround it with parentheses depending on the precedence and associativity of its parent.

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).

pretty' :: Pretty t => t -> Sem r (Doc ann) Source #

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.

findRep :: Ord a => [a] -> ([a], Int) Source #

findRep' :: Ord a => Map a Int -> Int -> [a] -> ([a], Int) Source #

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.

data Doc ann #

The abstract data type Doc ann represents pretty documents that have been annotated with data of type ann.

More specifically, a value of type Doc 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.

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

Instances

Instances details
Functor Doc

Alter the document’s annotations.

This instance makes Doc more flexible (because it can be used in Functor-polymorphic values), but fmap is much less readable compared to using reAnnotate in code that only works for Doc anyway. Consider using the latter when the type does not matter.

Instance details

Defined in Prettyprinter.Internal

Methods

fmap :: (a -> b) -> Doc a -> Doc b #

(<$) :: a -> Doc b -> Doc a #

IsString (Doc ann)
>>> pretty ("hello\nworld")
hello
world

This instance uses the Pretty Doc instance, and uses the same newline to line conversion.

Instance details

Defined in Prettyprinter.Internal

Methods

fromString :: String -> Doc ann #

Monoid (Doc ann)
mempty = emptyDoc
mconcat = hcat
>>> mappend "hello" "world" :: Doc ann
helloworld
Instance details

Defined in Prettyprinter.Internal

Methods

mempty :: Doc ann #

mappend :: Doc ann -> Doc ann -> Doc ann #

mconcat :: [Doc ann] -> Doc ann #

Semigroup (Doc ann)
x <> y = hcat [x, y]
>>> "hello" <> "world" :: Doc ann
helloworld
Instance details

Defined in Prettyprinter.Internal

Methods

(<>) :: Doc ann -> Doc ann -> Doc ann #

sconcat :: NonEmpty (Doc ann) -> Doc ann #

stimes :: Integral b => b -> Doc ann -> Doc ann #

Generic (Doc ann) 
Instance details

Defined in Prettyprinter.Internal

Associated Types

type Rep (Doc ann) :: Type -> Type #

Methods

from :: Doc ann -> Rep (Doc ann) x #

to :: Rep (Doc ann) x -> Doc ann #

Show (Doc ann)

(show doc) prettyprints document doc with defaultLayoutOptions, ignoring all annotations.

Instance details

Defined in Prettyprinter.Internal

Methods

showsPrec :: Int -> Doc ann -> ShowS #

show :: Doc ann -> String #

showList :: [Doc ann] -> ShowS #

IsString (Sem r (Doc ann)) Source # 
Instance details

Defined in Disco.Pretty.DSL

Methods

fromString :: String -> Sem r (Doc ann) #

type Rep (Doc ann) 
Instance details

Defined in Prettyprinter.Internal

type Rep (Doc ann) = D1 ('MetaData "Doc" "Prettyprinter.Internal" "prettyprinter-1.7.1-Fnq1Vt2JMTY81kvR0W9kdP" 'False) (((C1 ('MetaCons "Fail" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "Empty" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "Char" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Char)))) :+: (C1 ('MetaCons "Text" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)) :+: (C1 ('MetaCons "Line" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "FlatAlt" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann)))))) :+: ((C1 ('MetaCons "Cat" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann))) :+: (C1 ('MetaCons "Nest" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann))) :+: C1 ('MetaCons "Union" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann)) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann))))) :+: ((C1 ('MetaCons "Column" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Int -> Doc ann))) :+: C1 ('MetaCons "WithPageWidth" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (PageWidth -> Doc ann)))) :+: (C1 ('MetaCons "Nesting" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Int -> Doc ann))) :+: C1 ('MetaCons "Annotated" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ann) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Doc ann)))))))