lambdacube-compiler-0.5.0.0: LambdaCube 3D is a DSL to program GPUs

Safe HaskellNone
LanguageHaskell2010

LambdaCube.Compiler.Pretty

Synopsis

Documentation

pShow :: PShow a => a -> Doc Source

ppShow :: PShow a => a -> String Source

ppShow' :: Show a => a -> String Source

pOp :: (Ord a, PShow a1, PShow a2) => a -> Int -> Int -> Doc -> a -> a1 -> a2 -> Doc Source

pOp' :: (Ord a, PShow a1, PShow a2) => a -> Int -> Int -> Doc -> a -> a1 -> a2 -> Doc Source

pInfixl :: (PShow a, PShow a1) => Int -> Doc -> Int -> a -> a1 -> Doc Source

pInfixr :: (PShow a, PShow a1) => Int -> Doc -> Int -> a -> a1 -> Doc Source

pInfixr' :: (PShow a, PShow a1) => Int -> Doc -> Int -> a -> a1 -> Doc Source

pInfix :: (PShow a, PShow a1) => Int -> Doc -> Int -> a -> a1 -> Doc Source

pTyApp :: (PShow a, PShow a1) => Int -> a -> a1 -> Doc Source

pApps :: (PShow a, PShow a1) => Int -> a -> [a1] -> Doc Source

pApp :: (PShow a, PShow a1) => Int -> a -> a1 -> Doc Source

showRecord :: (PShow a, PShow a1) => [(a, a1)] -> Doc Source

pattern ESC :: [Char] -> [Char] -> [Char] Source

withEsc :: Show a => a -> [Char] -> [Char] Source

inRed :: [Char] -> [Char] Source

trace_ :: String -> a -> a Source

data Doc :: *

The abstract data type Doc represents pretty documents.

Doc is an instance of the Show class. (show doc) pretty prints document doc with a page width of 100 characters and a ribbon width of 40 characters.

show (text "hello" <$> text "world")

Which would return the string "hello\nworld", i.e.

hello
world

(<+>) :: Doc -> Doc -> Doc infixr 6

The document (x <+> y) concatenates document x and y with a space in between. (infixr 6)

(</>) :: Doc -> Doc -> Doc infixr 5

The document (x </> y) concatenates document x and y with a softline in between. This effectively puts x and y either next to each other (with a space in between) or underneath each other. (infixr 5)

(<$$>) :: Doc -> Doc -> Doc infixr 5

The document (x <$$> y) concatenates document x and y with a linebreak in between. (infixr 5)

hsep :: [Doc] -> Doc

The document (hsep xs) concatenates all documents xs horizontally with (<+>).

hcat :: [Doc] -> Doc

The document (hcat xs) concatenates all documents xs horizontally with (<>).

vcat :: [Doc] -> Doc

The document (vcat xs) concatenates all documents xs vertically with (<$$>). If a group undoes the line breaks inserted by vcat, all documents are directly concatenated.

punctuate :: Doc -> [Doc] -> [Doc]

(punctuate p xs) concatenates all documents in xs with document p except for the last document.

someText = map text ["words","in","a","tuple"]
test     = parens (align (cat (punctuate comma someText)))

This is layed out on a page width of 20 as:

(words,in,a,tuple)

But when the page width is 15, it is layed out as:

(words,
 in,
 a,
 tuple)

(If you want put the commas in front of their elements instead of at the end, you should use tupled or, in general, encloseSep.)

tupled :: [Doc] -> Doc

The document (tupled xs) comma separates the documents xs and encloses them in parenthesis. The documents are rendered horizontally if that fits the page. Otherwise they are aligned vertically. All comma separators are put in front of the elements.

braces :: Doc -> Doc

Document (braces x) encloses document x in braces, "{" and "}".

parens :: Doc -> Doc

Document (parens x) encloses document x in parenthesis, "(" and ")".

text :: String -> Doc

The document (text s) contains the literal string s. The string shouldn't contain any newline ('\n') characters. If the string contains newline characters, the function string should be used.

nest :: Int -> Doc -> Doc

The document (nest i x) renders document x with the current indentation level increased by i (See also hang, align and indent).

nest 2 (text "hello" <$> text "world") <$> text "!"

outputs as:

hello
  world
!