Copyright | (c) The University of Edinburgh 2016 |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Yi Zhen <s1563190@sms.ed.ac.uk> |
Stability | Unknown |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Provides a collection of pretty printer combinators, a set of API's that provides a way to easily print out text in a consistent format.
Originally designed by Philip Wadler's.
For more information you can refer to the original paper that serves as the basis for this libraries design: A prettier printer, by Philip Wadler, 2003.
- class Pretty a where
- printer :: Show a => Pretty a => a -> IO ()
- printLen :: Show a => Pretty a => Int -> a -> IO ()
- fullPrinter :: Show a => Pretty a => Style -> a -> IO ()
- pprint :: Pretty a => Int -> a -> IO ()
- pshow :: Pretty a => (Doc -> [Char]) -> Int -> a -> String
- pretty :: (Doc -> [Char]) -> Int -> DOC -> String
- (<>) :: DOC -> DOC -> DOC
- nil :: DOC
- nest :: Int -> DOC -> DOC
- text :: String -> DOC
- line :: DOC
- group :: DOC -> DOC
- parens :: DOC -> DOC
- layout :: Doc -> [Char]
- char :: Char -> DOC
- rep :: [DOC] -> DOC
- class Generic a
Documentation
Conversion of values to pretty printable String
s
Derived instances of Pretty
have the following properties
- The result of
ppPrec
is a syntactically correct Haskell expression containing only constants, given the fixity declarations in force at the point where the type is declared. It contains only the constructor names defined in the data type, parentheses, and spaces. When labelled constructor fields are used, braces, commas, field names, and equal signs are also used. - the representation will be enclosed in parentheses if the
precedence of the top-level constructor in
x
is less thand
(associativity is ignored). Thus, ifd
is0
then the result is never surrounded in parentheses; ifd
is11
it is always surrounded in parentheses, unless it is an atomic expression. - If the constructor is defined to be an infix operator, then
ppPrec
will produce infix applications of the constructor. - If the constructor is defined using record syntax, then
ppPrec
will produce the record-syntax form, with the fields given in the same order as the original declaration.
:: Int | the operator precedence of the enclosing context |
-> a | the value to be converted to a |
-> DOC | the result |
ppPrec
converts a value to a pretty printable DOC.
fullPrinter :: Show a => Pretty a => Style -> a -> IO () Source
The default Pretty Printer
class Generic a
Representable types of kind *. This class is derivable in GHC with the DeriveGeneric flag on.
Generic Bool | |
Generic Char | |
Generic Double | |
Generic Float | |
Generic Int | |
Generic Ordering | |
Generic () | |
Generic Arity | |
Generic Fixity | |
Generic Associativity | |
Generic [a] | |
Generic (U1 p) | |
Generic (Par1 p) | |
Generic (Maybe a) | |
Generic (Either a b) | |
Generic (Rec1 f p) | |
Generic (a, b) | |
Generic (Proxy * t) | |
Generic (K1 i c p) | |
Generic ((:+:) f g p) | |
Generic ((:*:) f g p) | |
Generic ((:.:) f g p) | |
Generic (a, b, c) | |
Generic (M1 i c f p) | |
Generic (a, b, c, d) | |
Generic (a, b, c, d, e) | |
Generic (a, b, c, d, e, f) | |
Generic (a, b, c, d, e, f, g) |