-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A generic, derivable, haskell pretty printer. -- -- GenericPretty is a haskell library that provides support for automatic -- derivation of pretty printing functions on user defined data types. -- The Pretty library -- http://www.haskell.org/ghc/docs/7.0.4/html/libraries/ghc-7.0.4/Pretty.html -- is used underneath, the work is done over Pretty.Doc types. -- -- The output provided by the library functions is identical to that of -- Prelude.show, except it has extra whitespace. -- -- This requires the use of the new GHC.Generics features: -- http://www.haskell.org/haskellwiki/Generics. As of 9.08.2011, -- these aren't present in the stable GHC releases, but seem to be -- present in the GHC HEAD development snapshots >= 7.1.20110601. -- -- The Generics used are based on those described in the paper A -- Generic Deriving Mechanism for Haskell : -- http://dreixel.net/research/pdf/gdmh.pdf . The changes from the -- original paper on the ghc implementation are described here: -- http://www.haskell.org/haskellwiki/Generics#Changes_from_the_paper. -- -- For more info and examples of usage please see the README file -- included in the package and the API at -- http://haggismcmutton.github.com/GenericPretty/ -- -- Installation of the package is straightforward, if needed, -- instructions can be found, for instance, here: -- http://www.haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package. @package GenericPretty @version 1.0.1 -- | GenericPretty is a haskell library that provides support for automatic -- derivation of pretty printing functions on user defined data types. -- The Pretty library is used underneath, the work is done over -- Doc types. -- -- The output provided by the library functions is identical to that of -- show, except it has extra whitespace. -- -- This requires the use of the new GHC.Generics features: -- http://www.haskell.org/haskellwiki/Generics. As of 9.08.2011, -- these aren't present in the stable GHC releases, but seem to be -- present in the GHC HEAD development snapshots >= 7.1.20110601. -- -- The Generics used are based on those described in the paper "A -- Generic Deriving Mechanism for Haskell" : -- http://dreixel.net/research/pdf/gdmh.pdf . There are however -- several changes between the mechanism described in the paper and the -- one implemented in GHC which are described here: -- http://www.haskell.org/haskellwiki/Generics#Changes_from_the_paper. -- -- For more info and examples of usage please see the README file -- included in the package module Text.PrettyPrint.GenericPretty -- | The default Pretty Printer, -- -- It uses the default style, defStyle pp :: Out a => a -> IO () -- | Semi-customizable pretty printer. Takes the lineLength as a parameter -- uses mode = PageMode and ribbonsPerLine = 1 ppLen :: Out a => Int -> a -> IO () -- | Customizable pretty printer, takes a user defined Style as a -- parameter and uses outputIO to obtain the result ppStyle :: Out a => Style -> a -> IO () -- | The default pretty printer returning Strings -- -- It uses the default style, defStyle pretty :: Out a => a -> String -- | Semi-customizable pretty printer. Takes the lineLength as a parameter -- uses mode = PageMode and ribbonsPerLine = 1 prettyLen :: Out a => Int -> a -> String -- | Customizable pretty printer, takes a user defined Style as a -- parameter and uses outputStr to obtain the result prettyStyle :: Out a => Style -> a -> String -- | fullPP is a fully customizable Pretty Printer Every other -- pretty printer just gives some default values to fullPP fullPP :: Out a => a -> Mode -> Int -> Float -> (TextDetails -> b -> b) -> b -> b -- | The default generic out method, converts the type into a sum of -- products and passes it on to the generic pretty printing functions, -- finally it concatenates all of the SDoc's -- -- It needs to be used in code to define the instance for Out -- -- For instance, given the declaration: -- --
-- data Tree a = Leaf a | Node (Tree a) (Tree a) deriving (Generic) ---- -- The user would need to write an instance declaration like: -- --
-- instance (Out a) => Out (Tree a) where -- docPrec = genOut ---- -- After doing this, the user can now use pretty printing function like -- pp and pretty on data of type Tree genOut :: (Generic a, GOut (Rep a)) => Int -> a -> Doc -- | outputIO transforms the text into strings and outputs it -- directly. -- -- This is one example of a function that can handle the text conversion -- for fullPP. outputIO :: TextDetails -> IO () -> IO () -- | outputStr just leaves the text as a string. This is usefull if -- you want to further process the pretty printed result. -- -- This is another example of a function that can handle the text -- conversion for fullPP. outputStr :: TextDetails -> String -> String -- | Utility function used to wrap the passed value in parens if the bool -- is true A single paren should never occupy a whole line, so they are -- concatenated to the first and last elements in the list, instead of -- just adding them to the list wrapParens :: Bool -> [Doc] -> [Doc] -- | The default Style used for pp and pretty -- (mode=PageMode, lineLength=100, ribbonsPerLine=1.5) defStyle :: Style -- | The class Out is the equivalent of Show -- -- Conversion of values to pretty printable Docs. -- -- Minimal complete definition: docPrec or doc. -- -- Derived instances of Out have the following properties -- --
-- data Tree a = Leaf a | Node (Tree a) (Tree a) deriving (Generic) ---- -- The derived instance of Out is equivalent to: -- --
-- instance (Out a) => Out (Tree a) where -- -- docPrec d (Leaf m) = Pretty.sep $ wrapParens (d > appPrec) $ -- text "Leaf" : [nest (constrLen + parenLen) (docPrec (appPrec+1) m)] -- where appPrec = 10 -- constrLen = 5; -- parenLen = if(d > appPrec) then 1 else 0 -- -- docPrec d (Node u v) = Pretty.sep $ wrapParens (d > appPrec) $ -- text "Node" : -- nest (constrLen + parenLen) (docPrec (appPrec+1) u) : -- [nest (constrLen + parenLen) (docPrec (appPrec+1) v)] -- where appPrec = 10 -- constrLen = 5 -- parenLen = if(d > appPrec) then 1 else 0 --class Out a docPrec :: Out a => Int -> a -> Doc doc :: Out a => a -> Doc docList :: Out a => [a] -> Doc -- | A rendering style data Style Style :: Mode -> Int -> Float -> Style -- | The rendering mode mode :: Style -> Mode -- | Length of line, in chars lineLength :: Style -> Int -- | Ratio of ribbon length to line length ribbonsPerLine :: Style -> Float -- | Representable types of kind *. This class is derivable in GHC with the -- XDeriveRepresentable flag on. class Generic a instance (Out a, Out b, Out c, Out d, Out e, Out f, Out g, Out h, Out i, Out j, Out k, Out l, Out m, Out n, Out o) => Out (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) instance (Out a, Out b, Out c, Out d, Out e, Out f, Out g, Out h, Out i, Out j, Out k, Out l, Out m, Out n) => Out (a, b, c, d, e, f, g, h, i, j, k, l, m, n) instance (Out a, Out b, Out c, Out d, Out e, Out f, Out g, Out h, Out i, Out j, Out k, Out l, Out m) => Out (a, b, c, d, e, f, g, h, i, j, k, l, m) instance (Out a, Out b, Out c, Out d, Out e, Out f, Out g, Out h, Out i, Out j, Out k, Out l) => Out (a, b, c, d, e, f, g, h, i, j, k, l) instance (Out a, Out b, Out c, Out d, Out e, Out f, Out g, Out h, Out i, Out j, Out k) => Out (a, b, c, d, e, f, g, h, i, j, k) instance (Out a, Out b, Out c, Out d, Out e, Out f, Out g, Out h, Out i, Out j) => Out (a, b, c, d, e, f, g, h, i, j) instance (Out a, Out b, Out c, Out d, Out e, Out f, Out g, Out h, Out i) => Out (a, b, c, d, e, f, g, h, i) instance (Out a, Out b, Out c, Out d, Out e, Out f, Out g, Out h) => Out (a, b, c, d, e, f, g, h) instance (Out a, Out b, Out c, Out d, Out e, Out f, Out g) => Out (a, b, c, d, e, f, g) instance (Out a, Out b, Out c, Out d, Out e, Out f) => Out (a, b, c, d, e, f) instance (Out a, Out b, Out c, Out d, Out e) => Out (a, b, c, d, e) instance (Out a, Out b, Out c, Out d) => Out (a, b, c, d) instance (Out a, Out b, Out c) => Out (a, b, c) instance (Out a, Out b) => Out (a, b) instance (Out a, Out b) => Out (Either a b) instance Out a => Out (Maybe a) instance Out Int instance Out Bool instance Out a => Out [a] instance Out Integer instance Out Char instance (GOut f, GOut g) => GOut (f :*: g) instance (GOut f, GOut g) => GOut (f :+: g) instance Out f => GOut (K1 t f) instance (GOut f, Constructor c) => GOut (M1 C c f) instance (GOut f, Selector c) => GOut (M1 S c f) instance (GOut f, Datatype c) => GOut (M1 D c f) instance GOut U1