Safe Haskell | None |
---|---|
Language | Haskell2010 |
TODO The syntax is quite light, so the precedence table is small:
operation | assoc | examples |
---|---|---|
application | left | f x y , f (g x) |
Pi,arrow | right | a -> b -> c , (a -> b) -> c |
lambda | none | λx → x |
annotation | right | a : t , a : t : s , (a : t) : t' |
%>>> let pp = prettyPut :: Term LambdaStar -> IO () %>>> let pp' = prettyPut :: Value LambdaStar -> IO () %>>> let s = LambdaStar
%>>> pp $ "f" @ "x"
@ "y"
f x y
%>>> pp $ pi_ "m" (Nat ~> sort_ s) s ("m" @@ "zero" ~> "x") s ∏m : Nat → ⋆. m zero → x
%>>> pp' $ lam_ "x" "x" λx → x
%>>> prettyPut ("x" -:- "t" -:- "s" :: Term LambdaStar) x : t : s
%>>> prettyPut (("x" -:- "t") -:- "s" :: Term LambdaStar) (x : t) : s
Note: we don't rename or disambiguate variables (in pretty-printing), so one have to be careful:
%>>> let latter = lams_ ["x", "x"] "x" :: Value LambdaStar
%>>> let former = lams_ ["f", "x"] ("f" valueApp
"x") valueApp
lams_ ["y", "x"] "y" :: Value LambdaStar
%>>> pp' latter λx x → x
%>>> pp' former λx x → x
but they are different:
%>>> print latter >> print former ValueLam "x" (Scope (ValueLam "x" (Scope (ValueCoerce (ValueVar (B "x")))))) ValueLam "x" (Scope (ValueLam "x" (Scope (ValueCoerce (ValueVar (F (B "x")))))))
Synopsis
- class PrettyPrec a where
- data PrettyM a
- type Doc = Doc ()
- ppp0 :: PrettyPrec a => a -> PrettyM Doc
- pppParens :: Bool -> PrettyM Doc -> PrettyM Doc
- class PrettyPrec1 f where
- ppp1 :: (PrettyPrec1 f, PrettyPrec a) => Prec -> f a -> PrettyM Doc
- prettyShow :: PrettyPrec a => a -> String
- prettyShowWith :: PrettyPrec a => Options () String -> a -> String
- prettyPut :: PrettyPrec a => a -> IO ()
- prettyPutWith :: PrettyPrec a => Options () String -> a -> IO ()
- pppMarkSym :: Sym -> PrettyM Doc
- pppFreshSym :: Sym -> PrettyM Doc
- pppScopedSym :: Sym -> (Doc -> PrettyM a) -> PrettyM a
- pppScopedIrrSym :: IrrSym -> (Doc -> PrettyM a) -> PrettyM a
- pppChar :: Char -> PrettyM Doc
- pppText :: String -> PrettyM Doc
- pppIntegral :: Integral a => a -> PrettyM Doc
- pppIntegralSub :: Integral a => a -> PrettyM Doc
- (<+>) :: PrettyM Doc -> PrettyM Doc -> PrettyM Doc
- (</>) :: PrettyM Doc -> PrettyM Doc -> PrettyM Doc
- ($$$) :: PrettyM Doc -> PrettyM Doc -> PrettyM Doc
- pppHsepPunctuated :: Doc -> [PrettyM Doc] -> PrettyM Doc
- pppSepPunctuated :: Doc -> [PrettyM Doc] -> PrettyM Doc
- pppCatPunctuated :: Doc -> [PrettyM Doc] -> PrettyM Doc
- pppColon :: PrettyM Doc
- pppComma_ :: Doc ()
- pppHang :: Int -> PrettyM Doc -> PrettyM Doc -> PrettyM Doc
- pppApplication :: Prec -> PrettyM Doc -> [PrettyM Doc] -> PrettyM Doc
- pppPi :: Prec -> [PPPi] -> PrettyM Doc -> PrettyM Doc
- data PPPi
- pppLambda :: Prec -> [Doc] -> PrettyM Doc -> PrettyM Doc
- pppAnnotation :: Prec -> PrettyM Doc -> PrettyM Doc -> PrettyM Doc
- pppAnnotationPi :: Prec -> PrettyM Doc -> [PPPi] -> PrettyM Doc -> PrettyM Doc
- pppHadron :: Set Sym -> PrettyM Doc
- pppQuark :: Sym -> PrettyM Doc
- pppQuarkElim :: Prec -> IrrSym -> (Doc -> PrettyM Doc) -> Map Sym (PrettyM Doc) -> PrettyM Doc -> PrettyM Doc
- data Prec
- = PrecDef
- | PrecAnn
- | PrecLambda
- | PrecPi
- | PrecApp
- predPrec :: Prec -> Prec
Class
class PrettyPrec a where Source #
Instances
A pretty-printing monad, keeping state of binded symbols.
Instances
Monad PrettyM Source # | |
Functor PrettyM Source # | |
Applicative PrettyM Source # | |
a ~ Doc => IsString (PrettyM a) Source # | |
Defined in Language.PTS.Pretty fromString :: String -> PrettyM a Source # | |
a ~ Doc => Semigroup (PrettyM a) Source # | |
a ~ Doc => Monoid (PrettyM a) Source # | |
a ~ Doc => PrettyPrec (PrettyM a) Source # | |
class PrettyPrec1 f where Source #
Instances
PrettyPrec1 Maybe Source # | |
PrettyPrec a => PrettyPrec1 (Var a) Source # | |
PrettyPrec1 t => PrettyPrec1 (UTerm t) Source # | |
Specification s => PrettyPrec1 (TermChk s) Source # | |
Specification s => PrettyPrec1 (TermInf s) Source # | |
(Specification s, PrettyPrec err) => PrettyPrec1 (ValueElim err s) Source # | |
(Specification s, PrettyPrec err) => PrettyPrec1 (ValueIntro err s) Source # | |
ppp1 :: (PrettyPrec1 f, PrettyPrec a) => Prec -> f a -> PrettyM Doc Source #
Helper useful to define PrettyPrec
in terms of PrettyPrec1
.
Convience functons
prettyShow :: PrettyPrec a => a -> String Source #
prettyShowWith :: PrettyPrec a => Options () String -> a -> String Source #
prettyPut :: PrettyPrec a => a -> IO () Source #
prettyPutWith :: PrettyPrec a => Options () String -> a -> IO () Source #
Symbols
pppMarkSym :: Sym -> PrettyM Doc Source #
Mark symbol name as used, but print it as is
>>>
prettyPut' $ pppMarkSym "x" <+> pppMarkSym "x" <+> pppFreshSym "x"
x x x₁
pppFreshSym :: Sym -> PrettyM Doc Source #
Generate fresh name.
>>>
prettyPut' $ pppFreshSym "x" <+> pppFreshSym "x" <+> pppFreshSym "x"
x x₁ x₂
pppScopedSym :: Sym -> (Doc -> PrettyM a) -> PrettyM a Source #
Scoped name usage. See 'PrettyPrec
>>>
prettyPut $ pppFreshSym "x" <+> pppParens True (pppScopedSym "x" (\x -> "\\" <> return x <> "...")) <+> pppFreshSym "x"
x (\x₁...) x₁
Combinators
The pretty-compact
combinators wrapped in PrettyM
.
Syntax
Combinators for different syntactical constructs.
pppApplication :: Prec -> PrettyM Doc -> [PrettyM Doc] -> PrettyM Doc Source #
Render application.
>>>
prettyPut' $ pppApplication PrecDef "f" ["a", "b", "c", "d"]
f a b c d
>>>
prettyPut' $ pppApplication PrecDef "f" ["aaaa", "bbbb", "cccc", "dddd"]
f aaaa bbbb cccc dddd
pppPi :: Prec -> [PPPi] -> PrettyM Doc -> PrettyM Doc Source #
Render (dependent) function space.
>>>
prettyPut' $ pppPi PrecDef [PPPi "n" "Nat"] "Vec a n"
∏ (n : Nat) → Vec a n
>>>
prettyPut' $ pppPi PrecDef [PPPi "n" "Nat", PPForall "a"] "Vec a n"
∏ (n : Nat) → ∀ a → Vec a n
>>>
prettyPut' $ pppPi PrecDef [PPPi "n" "Nat", PPForall "a", PPArrow "Vec a n"] "r"
∏ (n : Nat) → ∀ a → Vec a n → r
>>>
prettyPut' $ pppPi PrecDef [PPArrow (pppPi PrecPi [PPArrow "a"] "b"), PPArrow "a"] "b"
(a → b) → a → b
Specifies how to print (function) types.
pppLambda :: Prec -> [Doc] -> PrettyM Doc -> PrettyM Doc Source #
Render lambda abstraction.
>>>
prettyPut' $ pppLambda PrecDef [] "x"
x
>>>
prettyPut' $ pppLambda PrecDef ["x", "y", "z"] "long body"
λ x y z → long body
pppAnnotationPi :: Prec -> PrettyM Doc -> [PPPi] -> PrettyM Doc -> PrettyM Doc Source #
Render type annotation with (possibly) pi-type.
>>>
prettyPut' $ pppAnnotationPi PrecDef "x" [] "t"
x : t
>>>
prettyPut' $ pppAnnotationPi PrecDef "f" [PPArrow (pppPi PrecPi [PPArrow "a"] "b"), PPArrow "a"] "b"
f : (a → b) → a → b
>>>
prettyPut' $ pppAnnotationPi PrecDef "myfunc" [PPPi "n" "Nat", PPForall "a", PPArrow "Vec a n"] "r"
myfunc : ∏ (n : Nat) → ∀ a → Vec a n → r
Hadron
pppQuarkElim :: Prec -> IrrSym -> (Doc -> PrettyM Doc) -> Map Sym (PrettyM Doc) -> PrettyM Doc -> PrettyM Doc Source #