ghc-6.12.1: The GHC APISource codeContentsIndex
Outputable
Contents
Type classes
Pretty printing combinators
Converting SDoc into strings and outputing it
Controlling the style in which output is printed
Error handling and debugging utilities
Description

This module defines classes and functions for pretty-printing. It also exports a number of helpful debugging and other utilities such as trace and panic.

The interface to this module is very similar to the standard Hughes-PJ pretty printing module, except that it exports a number of additional functions that are rarely used, and works over the SDoc type.

Synopsis
class Outputable a where
ppr :: a -> SDoc
class Outputable a => OutputableBndr a where
pprBndr :: BindingSite -> a -> SDoc
type SDoc = PprStyle -> Doc
docToSDoc :: Doc -> SDoc
interppSP :: Outputable a => [a] -> SDoc
interpp'SP :: Outputable a => [a] -> SDoc
pprQuotedList :: Outputable a => [a] -> SDoc
pprWithCommas :: (a -> SDoc) -> [a] -> SDoc
empty :: SDoc
nest :: Int -> SDoc -> SDoc
char :: Char -> SDoc
text :: String -> SDoc
ftext :: FastString -> SDoc
ptext :: LitString -> SDoc
int :: Int -> SDoc
integer :: Integer -> SDoc
float :: Float -> SDoc
double :: Double -> SDoc
rational :: Rational -> SDoc
parens :: SDoc -> SDoc
cparen :: Bool -> SDoc -> SDoc
brackets :: SDoc -> SDoc
braces :: SDoc -> SDoc
quotes :: SDoc -> SDoc
doubleQuotes :: SDoc -> SDoc
angleBrackets :: SDoc -> SDoc
semi :: SDoc
comma :: SDoc
colon :: SDoc
dcolon :: SDoc
space :: SDoc
equals :: SDoc
dot :: SDoc
arrow :: SDoc
lparen :: SDoc
rparen :: SDoc
lbrack :: SDoc
rbrack :: SDoc
lbrace :: SDoc
rbrace :: SDoc
underscore :: SDoc
(<>) :: SDoc -> SDoc -> SDoc
(<+>) :: SDoc -> SDoc -> SDoc
hcat :: [SDoc] -> SDoc
hsep :: [SDoc] -> SDoc
($$) :: SDoc -> SDoc -> SDoc
($+$) :: SDoc -> SDoc -> SDoc
vcat :: [SDoc] -> SDoc
sep :: [SDoc] -> SDoc
cat :: [SDoc] -> SDoc
fsep :: [SDoc] -> SDoc
fcat :: [SDoc] -> SDoc
hang :: SDoc -> Int -> SDoc -> SDoc
punctuate :: SDoc -> [SDoc] -> [SDoc]
ppWhen :: Bool -> SDoc -> SDoc
ppUnless :: Bool -> SDoc -> SDoc
speakNth :: Int -> SDoc
speakNTimes :: Int -> SDoc
speakN :: Int -> SDoc
speakNOf :: Int -> SDoc -> SDoc
plural :: [a] -> SDoc
printSDoc :: SDoc -> PprStyle -> IO ()
printErrs :: Doc -> IO ()
hPrintDump :: Handle -> SDoc -> IO ()
printDump :: SDoc -> IO ()
printForC :: Handle -> SDoc -> IO ()
printForAsm :: Handle -> SDoc -> IO ()
printForUser :: Handle -> PrintUnqualified -> SDoc -> IO ()
printForUserPartWay :: Handle -> Int -> PrintUnqualified -> SDoc -> IO ()
pprCode :: CodeStyle -> SDoc -> SDoc
mkCodeStyle :: CodeStyle -> PprStyle
showSDoc :: SDoc -> String
showSDocOneLine :: SDoc -> String
showSDocForUser :: PrintUnqualified -> SDoc -> String
showSDocDebug :: SDoc -> String
showSDocDump :: SDoc -> String
showSDocDumpOneLine :: SDoc -> String
showPpr :: Outputable a => a -> String
showSDocUnqual :: SDoc -> String
showsPrecSDoc :: Int -> SDoc -> ShowS
pprInfixVar :: Bool -> SDoc -> SDoc
pprPrefixVar :: Bool -> SDoc -> SDoc
pprHsChar :: Char -> SDoc
pprHsString :: FastString -> SDoc
pprHsInfix :: Outputable name => name -> SDoc
pprHsVar :: Outputable name => name -> SDoc
pprFastFilePath :: FastString -> SDoc
data BindingSite
= LambdaBind
| CaseBind
| LetBind
data PprStyle
data CodeStyle
= CStyle
| AsmStyle
type PrintUnqualified = (QueryQualifyName, QueryQualifyModule)
alwaysQualify :: PrintUnqualified
neverQualify :: PrintUnqualified
data QualifyName
= NameUnqual
| NameQual ModuleName
| NameNotInScope1
| NameNotInScope2
getPprStyle :: (PprStyle -> SDoc) -> SDoc
withPprStyle :: PprStyle -> SDoc -> SDoc
withPprStyleDoc :: PprStyle -> SDoc -> Doc
pprDeeper :: SDoc -> SDoc
pprDeeperList :: ([SDoc] -> SDoc) -> [SDoc] -> SDoc
pprSetDepth :: Depth -> SDoc -> SDoc
codeStyle :: PprStyle -> Bool
userStyle :: PprStyle -> Bool
debugStyle :: PprStyle -> Bool
dumpStyle :: PprStyle -> Bool
asmStyle :: PprStyle -> Bool
ifPprDebug :: SDoc -> SDoc
qualName :: PprStyle -> QueryQualifyName
qualModule :: PprStyle -> QueryQualifyModule
mkErrStyle :: PrintUnqualified -> PprStyle
defaultErrStyle :: PprStyle
defaultDumpStyle :: PprStyle
defaultUserStyle :: PprStyle
mkUserStyle :: PrintUnqualified -> Depth -> PprStyle
data Depth
= AllTheWay
| PartWay Int
pprPanic :: String -> SDoc -> a
assertPprPanic :: String -> Int -> SDoc -> a
pprPanicFastInt :: String -> SDoc -> FastInt
pprPgmError :: String -> SDoc -> a
pprTrace :: String -> SDoc -> a -> a
warnPprTrace :: Bool -> String -> Int -> SDoc -> a -> a
trace :: String -> a -> a
pgmError :: String -> a
panic :: String -> a
panicFastInt :: String -> FastInt
assertPanic :: String -> Int -> a
Type classes
class Outputable a whereSource
Class designating that some type has an SDoc representation
Methods
ppr :: a -> SDocSource
class Outputable a => OutputableBndr a whereSource
When we print a binder, we often want to print its type too. The OutputableBndr class encapsulates this idea.
Methods
pprBndr :: BindingSite -> a -> SDocSource
Pretty printing combinators
type SDoc = PprStyle -> DocSource
docToSDoc :: Doc -> SDocSource
interppSP :: Outputable a => [a] -> SDocSource
Returns the seperated concatenation of the pretty printed things.
interpp'SP :: Outputable a => [a] -> SDocSource
Returns the comma-seperated concatenation of the pretty printed things.
pprQuotedList :: Outputable a => [a] -> SDocSource

Returns the comma-seperated concatenation of the quoted pretty printed things.

 [x,y,z]  ==>  `x', `y', `z'
pprWithCommasSource
::
=> a -> SDocThe things to be pretty printed
-> [a]SDoc where the things have been pretty printed, comma-separated and finally packed into a paragraph.
-> SDoc
empty :: SDocSource
nest :: Int -> SDoc -> SDocSource
Indent SDoc some specified amount
char :: Char -> SDocSource
text :: String -> SDocSource
ftext :: FastString -> SDocSource
ptext :: LitString -> SDocSource
int :: Int -> SDocSource
integer :: Integer -> SDocSource
float :: Float -> SDocSource
double :: Double -> SDocSource
rational :: Rational -> SDocSource
parens :: SDoc -> SDocSource
cparen :: Bool -> SDoc -> SDocSource
brackets :: SDoc -> SDocSource
braces :: SDoc -> SDocSource
quotes :: SDoc -> SDocSource
doubleQuotes :: SDoc -> SDocSource
angleBrackets :: SDoc -> SDocSource
semi :: SDocSource
comma :: SDocSource
colon :: SDocSource
dcolon :: SDocSource
space :: SDocSource
equals :: SDocSource
dot :: SDocSource
arrow :: SDocSource
lparen :: SDocSource
rparen :: SDocSource
lbrack :: SDocSource
rbrack :: SDocSource
lbrace :: SDocSource
rbrace :: SDocSource
underscore :: SDocSource
(<>) :: SDoc -> SDoc -> SDocSource
Join two SDoc together horizontally without a gap
(<+>) :: SDoc -> SDoc -> SDocSource
Join two SDoc together horizontally with a gap between them
hcat :: [SDoc] -> SDocSource
Concatenate SDoc horizontally
hsep :: [SDoc] -> SDocSource
Concatenate SDoc horizontally with a space between each one
($$) :: SDoc -> SDoc -> SDocSource
Join two SDoc together vertically; if there is no vertical overlap it dovetails the two onto one line
($+$) :: SDoc -> SDoc -> SDocSource
Join two SDoc together vertically
vcat :: [SDoc] -> SDocSource
Concatenate SDoc vertically with dovetailing
sep :: [SDoc] -> SDocSource
Separate: is either like hsep or like vcat, depending on what fits
cat :: [SDoc] -> SDocSource
Catenate: is either like hcat or like vcat, depending on what fits
fsep :: [SDoc] -> SDocSource
A paragraph-fill combinator. It's much like sep, only it keeps fitting things on one line until it can't fit any more.
fcat :: [SDoc] -> SDocSource
This behaves like fsep, but it uses <> for horizontal conposition rather than <+>
hangSource
:: SDocThe header
-> IntAmount to indent the hung body
-> SDocThe hung body, indented and placed below the header
-> SDoc
punctuateSource
:: SDocThe punctuation
-> [SDoc]The list that will have punctuation added between every adjacent pair of elements
-> [SDoc]Punctuated list
ppWhen :: Bool -> SDoc -> SDocSource
ppUnless :: Bool -> SDoc -> SDocSource
speakNth :: Int -> SDocSource

Converts an integer to a verbal index:

 speakNth 1 = text "first"
 speakNth 5 = text "fifth"
 speakNth 21 = text "21st"
speakNTimes :: Int -> SDocSource

Converts a strictly positive integer into a number of times:

 speakNTimes 1 = text "once"
 speakNTimes 2 = text "twice"
 speakNTimes 4 = text "4 times"
speakN :: Int -> SDocSource

Converts an integer to a verbal multiplicity:

 speakN 0 = text "none"
 speakN 5 = text "five"
 speakN 10 = text "10"
speakNOf :: Int -> SDoc -> SDocSource

Converts an integer and object description to a statement about the multiplicity of those objects:

 speakNOf 0 (text "melon") = text "no melons"
 speakNOf 1 (text "melon") = text "one melon"
 speakNOf 3 (text "melon") = text "three melons"
plural :: [a] -> SDocSource

Determines the pluralisation suffix appropriate for the length of a list:

 plural [] = char 's'
 plural ["Hello"] = empty
 plural ["Hello", "World"] = char 's'
Converting SDoc into strings and outputing it
printSDoc :: SDoc -> PprStyle -> IO ()Source
printErrs :: Doc -> IO ()Source
hPrintDump :: Handle -> SDoc -> IO ()Source
printDump :: SDoc -> IO ()Source
printForC :: Handle -> SDoc -> IO ()Source
printForAsm :: Handle -> SDoc -> IO ()Source
printForUser :: Handle -> PrintUnqualified -> SDoc -> IO ()Source
printForUserPartWay :: Handle -> Int -> PrintUnqualified -> SDoc -> IO ()Source
pprCode :: CodeStyle -> SDoc -> SDocSource
mkCodeStyle :: CodeStyle -> PprStyleSource
showSDoc :: SDoc -> StringSource
showSDocOneLine :: SDoc -> StringSource
showSDocForUser :: PrintUnqualified -> SDoc -> StringSource
showSDocDebug :: SDoc -> StringSource
showSDocDump :: SDoc -> StringSource
showSDocDumpOneLine :: SDoc -> StringSource
showPpr :: Outputable a => a -> StringSource
showSDocUnqual :: SDoc -> StringSource
showsPrecSDoc :: Int -> SDoc -> ShowSSource
pprInfixVar :: Bool -> SDoc -> SDocSource
pprPrefixVar :: Bool -> SDoc -> SDocSource
pprHsChar :: Char -> SDocSource
Special combinator for showing character literals.
pprHsString :: FastString -> SDocSource
Special combinator for showing string literals.
pprHsInfix :: Outputable name => name -> SDocSource
pprHsVar :: Outputable name => name -> SDocSource
pprFastFilePath :: FastString -> SDocSource
Controlling the style in which output is printed
data BindingSite Source
BindingSite is used to tell the thing that prints binder what language construct is binding the identifier. This can be used to decide how much info to print.
Constructors
LambdaBind
CaseBind
LetBind
data PprStyle Source
data CodeStyle Source
Constructors
CStyle
AsmStyle
type PrintUnqualified = (QueryQualifyName, QueryQualifyModule)Source
alwaysQualify :: PrintUnqualifiedSource
neverQualify :: PrintUnqualifiedSource
data QualifyName Source
Constructors
NameUnqual
NameQual ModuleName
NameNotInScope1
NameNotInScope2
getPprStyle :: (PprStyle -> SDoc) -> SDocSource
withPprStyle :: PprStyle -> SDoc -> SDocSource
withPprStyleDoc :: PprStyle -> SDoc -> DocSource
pprDeeper :: SDoc -> SDocSource
pprDeeperList :: ([SDoc] -> SDoc) -> [SDoc] -> SDocSource
pprSetDepth :: Depth -> SDoc -> SDocSource
codeStyle :: PprStyle -> BoolSource
userStyle :: PprStyle -> BoolSource
debugStyle :: PprStyle -> BoolSource
dumpStyle :: PprStyle -> BoolSource
asmStyle :: PprStyle -> BoolSource
ifPprDebug :: SDoc -> SDocSource
qualName :: PprStyle -> QueryQualifyNameSource
qualModule :: PprStyle -> QueryQualifyModuleSource
mkErrStyle :: PrintUnqualified -> PprStyleSource
Style for printing error messages
defaultErrStyle :: PprStyleSource
defaultDumpStyle :: PprStyleSource
defaultUserStyle :: PprStyleSource
mkUserStyle :: PrintUnqualified -> Depth -> PprStyleSource
data Depth Source
Constructors
AllTheWay
PartWay Int
Error handling and debugging utilities
pprPanic :: String -> SDoc -> aSource
Throw an exception saying bug in GHC
assertPprPanic :: String -> Int -> SDoc -> aSource
Panic with an assertation failure, recording the given file and line number. Should typically be accessed with the ASSERT family of macros
pprPanicFastInt :: String -> SDoc -> FastIntSource
Specialization of pprPanic that can be safely used with FastInt
pprPgmError :: String -> SDoc -> aSource
Throw an exception saying bug in pgm being compiled (used for unusual program errors)
pprTrace :: String -> SDoc -> a -> aSource
If debug output is on, show some SDoc on the screen
warnPprTrace :: Bool -> String -> Int -> SDoc -> a -> aSource
Just warn about an assertion failure, recording the given file and line number. Should typically be accessed with the WARN macros
trace :: String -> a -> aSource
When called, trace outputs the string in its first argument, before returning the second argument as its result. The trace function is not referentially transparent, and should only be used for debugging, or for monitoring execution. Some implementations of trace may decorate the string that's output to indicate that you're tracing. The function is implemented on top of putTraceMsg.
pgmError :: String -> aSource
panic :: String -> aSource
panicFastInt :: String -> FastIntSource
assertPanic :: String -> Int -> aSource
Produced by Haddock version 2.6.0