bench-show-0.3.2: Show, plot and compare benchmark results
Copyright(c) 2022 Composewell Technologies
LicenseBSD-style
Maintainerharendra.kumar@gmail.com
Stabilityexperimental
PortabilityGHC
Safe HaskellSafe-Inferred
LanguageHaskell2010

BenchShow.Internal.Pretty

Description

 
Synopsis

Documentation

data Doc #

The abstract data type Doc represents pretty documents.

More specifically, a value of type Doc represents a non-empty set of possible renderings of a document. The rendering functions select one of these possibilities.

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

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

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

hello
world

Instances

Instances details
Show Doc 
Instance details

Defined in Text.PrettyPrint.ANSI.Leijen.Internal

Methods

showsPrec :: Int -> Doc -> ShowS #

show :: Doc -> String #

showList :: [Doc] -> ShowS #

IsString Doc 
Instance details

Defined in Text.PrettyPrint.ANSI.Leijen.Internal

Methods

fromString :: String -> Doc #

Semigroup Doc 
Instance details

Defined in Text.PrettyPrint.ANSI.Leijen.Internal

Methods

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

sconcat :: NonEmpty Doc -> Doc #

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

Monoid Doc 
Instance details

Defined in Text.PrettyPrint.ANSI.Leijen.Internal

Methods

mempty :: Doc #

mappend :: Doc -> Doc -> Doc #

mconcat :: [Doc] -> Doc #

Pretty Doc 
Instance details

Defined in Text.PrettyPrint.ANSI.Leijen.Internal

Methods

pretty :: Doc -> Doc #

prettyList :: [Doc] -> Doc #

dullred :: Doc -> Doc #

Displays a document with the dull red forecolor

dullgreen :: Doc -> Doc #

Displays a document with the dull green forecolor

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

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

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.

fill :: Int -> Doc -> Doc #

The document (fill i x) renders document x. It than appends spaces until the width is equal to i. If the width of x is already larger, nothing is appended. This combinator is quite useful in practice to output a list of bindings. The following example demonstrates this.

types  = [("empty","Doc")
         ,("nest","Int -> Doc -> Doc")
         ,("linebreak","Doc")]

ptype (name,tp)
       = fill 6 (text name) <+> text "::" <+> text tp

test   = text "let" <+> align (vcat (map ptype types))

Which is layed out as:

let empty  :: Doc
    nest   :: Int -> Doc -> Doc
    linebreak :: Doc

indent :: Int -> Doc -> Doc #

The document (indent i x) indents document x with i spaces.

test  = indent 4 (fillSep (map text
        (words "the indent combinator indents these words !")))

Which lays out with a page width of 20 as:

    the indent
    combinator
    indents these
    words !

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.

putDoc :: Doc -> IO () #

The action (putDoc doc) pretty prints document doc to the standard output, with a page width of 80 characters and a ribbon width of 32 characters.

main :: IO ()
main = do{ putDoc (text "hello" <+> text "world") }

Which would output

hello world

Any ANSI colorisation in doc will be output.