Language.Haskell.TH.PprLib

template-haskell-2.18.0.0: Support library for Template Haskell

Safe Haskell | Safe
Language | Haskell2010

Language.Haskell.TH.PprLib

Contents

- The document type
- Primitive Documents
- Converting values into documents
- Wrapping documents in delimiters
- Combining documents
- Predicates on documents

Description

Monadic front-end to Text.PrettyPrint

Synopsis

- type Doc = PprM Doc
- data PprM a
- empty :: Doc
- semi :: Doc
- comma :: Doc
- colon :: Doc
- dcolon :: Doc
- space :: Doc
- equals :: Doc
- arrow :: Doc
- lparen :: Doc
- rparen :: Doc
- lbrack :: Doc
- rbrack :: Doc
- lbrace :: Doc
- rbrace :: Doc
- text :: String -> Doc
- char :: Char -> Doc
- ptext :: String -> Doc
- int :: Int -> Doc
- integer :: Integer -> Doc
- float :: Float -> Doc
- double :: Double -> Doc
- rational :: Rational -> Doc
- parens :: Doc -> Doc
- brackets :: Doc -> Doc
- braces :: Doc -> Doc
- quotes :: Doc -> Doc
- doubleQuotes :: Doc -> Doc
- (<>) :: Doc -> Doc -> Doc
- (<+>) :: Doc -> Doc -> Doc
- hcat :: [Doc] -> Doc
- hsep :: [Doc] -> Doc
- ($$) :: Doc -> Doc -> Doc
- ($+$) :: Doc -> Doc -> Doc
- vcat :: [Doc] -> Doc
- sep :: [Doc] -> Doc
- cat :: [Doc] -> Doc
- fsep :: [Doc] -> Doc
- fcat :: [Doc] -> Doc
- nest :: Int -> Doc -> Doc
- hang :: Doc -> Int -> Doc -> Doc
- punctuate :: Doc -> [Doc] -> [Doc]
- isEmpty :: Doc -> PprM Bool
- to_HPJ_Doc :: Doc -> Doc
- pprName :: Name -> Doc
- pprName' :: NameIs -> Name -> Doc

# The document type

type Doc = PprM Doc Source #

data PprM a Source #

#### Instances

Instances details

Applicative PprM Source # |
Instance details Defined in Language.Haskell.TH.PprLib Methods pure :: a -> PprM a Source # (<*>) :: PprM (a -> b) -> PprM a -> PprM b Source # liftA2 :: (a -> b -> c) -> PprM a -> PprM b -> PprM c Source # (*>) :: PprM a -> PprM b -> PprM b Source # (<*) :: PprM a -> PprM b -> PprM a Source #
Functor PprM Source # |
Instance details Defined in Language.Haskell.TH.PprLib Methods fmap :: (a -> b) -> PprM a -> PprM b Source # (<$) :: a -> PprM b -> PprM a Source #
Monad PprM Source # |
Instance details Defined in Language.Haskell.TH.PprLib Methods (>>=) :: PprM a -> (a -> PprM b) -> PprM b Source # (>>) :: PprM a -> PprM b -> PprM b Source # return :: a -> PprM a Source #
Show Doc Source # |
Instance details Defined in Language.Haskell.TH.PprLib Methods showsPrec :: Int -> Doc -> ShowS Source # show :: Doc -> String Source # showList :: [Doc] -> ShowS Source #

# Primitive Documents

empty Source #

Arguments

:: Doc | An empty document

semi Source #

Arguments

:: Doc | A ';' character

comma Source #

Arguments

:: Doc | A ',' character

colon Source #

Arguments

:: Doc | A `:` character

dcolon Source #

Arguments

:: Doc | A "::" string

space Source #

Arguments

:: Doc | A space character

equals Source #

Arguments

:: Doc | A '=' character

arrow Source #

Arguments

:: Doc | A "->" string

lparen Source #

Arguments

:: Doc | A '(' character

rparen Source #

Arguments

:: Doc | A ')' character

lbrack Source #

Arguments

:: Doc | A '[' character

rbrack Source #

Arguments

:: Doc | A ']' character

lbrace Source #

Arguments

:: Doc | A '{' character

rbrace Source #

Arguments

:: Doc | A '}' character

# Converting values into documents

text :: String -> Doc Source #

char :: Char -> Doc Source #

ptext :: String -> Doc Source #

int :: Int -> Doc Source #

integer :: Integer -> Doc Source #

float :: Float -> Doc Source #

double :: Double -> Doc Source #

rational :: Rational -> Doc Source #

# Wrapping documents in delimiters

parens Source #

Arguments

:: Doc |
-> Doc | Wrap document in `(...)`

brackets Source #

Arguments

:: Doc |
-> Doc | Wrap document in `[...]`

braces Source #

Arguments

:: Doc |
-> Doc | Wrap document in `{...}`

quotes Source #

Arguments

:: Doc |
-> Doc | Wrap document in `'...'`

doubleQuotes Source #

Arguments

:: Doc |
-> Doc | Wrap document in `"..."`

# Combining documents

(<>) infixl 6 Source #

Arguments

:: Doc |
-> Doc |
-> Doc | Beside

(<+>) infixl 6 Source #

Arguments

:: Doc |
-> Doc |
-> Doc | Beside, separated by space

hcat Source #

Arguments

:: [Doc] |
-> Doc | List version of `<>`

hsep Source #

Arguments

:: [Doc] |
-> Doc | List version of `<+>`

($$) infixl 5 Source #

Arguments

:: Doc |
-> Doc |
-> Doc | Above; if there is no overlap it "dovetails" the two

($+$) infixl 5 Source #

Arguments

:: Doc |
-> Doc |
-> Doc | Above, without dovetailing.

vcat Source #

Arguments

:: [Doc] |
-> Doc | List version of `$$`

sep Source #

Arguments

:: [Doc] |
-> Doc | Either hsep or vcat

cat Source #

Arguments

:: [Doc] |
-> Doc | Either hcat or vcat

fsep Source #

Arguments

:: [Doc] |
-> Doc | "Paragraph fill" version of sep

fcat Source #

Arguments

:: [Doc] |
-> Doc | "Paragraph fill" version of cat

nest Source #

Arguments

:: Int |
-> Doc |
-> Doc | Nested

hang Source #

Arguments

:: Doc |
-> Int |
-> Doc |
-> Doc |
    hang d1 n d2 = sep [d1, nest n d2]

punctuate Source #

Arguments

:: Doc |
-> [Doc] |
-> [Doc] |
    punctuate p [d1, ... dn] = [d1 <> p, d2 <> p, ... dn-1 <> p, dn]

# Predicates on documents

isEmpty Source #

Arguments

:: Doc |
-> PprM Bool | Returns `True` if the document is empty

to_HPJ_Doc :: Doc -> Doc Source #

pprName :: Name -> Doc Source #

pprName' :: NameIs -> Name -> Doc Source #