-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A generic, derivable, haskell pretty printer. -- -- GenericPretty is a Haskell library that supports automatic derivation -- of pretty printing functions on user defined data types. -- -- The form of geenrics used is based on that introduced in the paper: -- Magalhaes, Dijkstra, Jeuring, and Loh, A Generic Deriving Mechanism -- for Haskell, 3'rd ACM Symposium on Haskell, pp. 37-48, September 2010, -- http://dx.doi.org/10.1145/1863523.1863529. Changes from the -- original paper in the GHC implementation are described here: -- http://www.haskell.org/haskellwiki/Generics#Changes_from_the_paper. -- -- This package requires the use of the new GHC.Generics features -- http://www.haskell.org/haskellwiki/Generics, present from GHC -- 7.2. Use of these features is indicated by the DeriveGeneric pragma. -- or the flag -XDeriveGeneric. -- -- Pretty printing produces values of type Pretty.Doc, using the Pretty -- library -- http://www.haskell.org/ghc/docs/7.0.4/html/libraries/ghc-7.0.4/Pretty.html. -- -- The Pretty library plans to incorporate a Style datatype to control -- details of printing (such as line length). The library MyPretty is -- provided as a thin wrapper around the Pretty library, to support Style -- related features. Once the Pretty library supports Style, MyPretty -- will become obsolete and be replaced by Pretty. -- -- The output provided is a pretty printed version of that provided by -- Prelude.show. That is, rendering the document provided by this pretty -- printer yields an output identical to that of Prelude.show, except for -- extra whitespace. -- -- For information about the functions exported by the package please see -- the API linked further down this page. For examples of usage, both -- basic and more complex see the README file and the haskell source code -- files in the TestSuite folder, both included in the package. Finally -- for installation instructions also see the README file or this page: -- http://www.haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package @package GenericPretty @version 1.1.9 -- | MyPretty is a library that can be used in conjuncture with -- Text.PrettyPrint.GenericPretty. -- -- The Pretty -- library(http://www.haskell.org/ghc/docs/7.0.4/html/libraries/ghc-7.0.4/Pretty.html) -- plans to incorporate a Style datatype to control details of -- printing (such as line length). The library MyPretty is provided as a -- thin wrapper around the Pretty library, to support Style -- related features. Once the Pretty library supports Style, -- MyPretty will become obsolete and be replaced by Pretty. -- -- This library can be imported if the user wants to make custom pretty -- printing definitions for his types or define a custom printing -- Style. The syntax used for defining custom documents is that of -- Pretty and Text.PrettyPrint.HughesPJ. -- -- For an example of a custom definition for a data type and usage of a -- custom Style see the README file and the haskell source files under -- TestSuite, both included in the package. module Text.PrettyPrint.MyPretty -- | 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 -- | Render a document using a particular Style. renderStyle :: Style -> Doc -> String -- | The default Syle (mode=PageMode, lineLength=80, -- ribbonsPerLine=1.5) style :: Style -- | GenericPretty is a Haskell library that supports automatic derivation -- of pretty printing functions on user defined data types. -- -- The output provided is a pretty printed version of that provided by -- show. That is, rendering the document provided by this pretty -- printer yields an output identical to that of show, except for -- extra whitespace. -- -- For examples of usage please see the README file included in the -- package. -- -- For more information see the HackageDB project page: -- http://hackage.haskell.org/package/GenericPretty-1.1.9 module Text.PrettyPrint.GenericPretty -- | The class Out is the equivalent of Show -- -- It provides conversion of values to pretty printable Pretty.Doc's. -- -- 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 -- | The default Pretty Printer, -- -- Equivalent to: -- --
-- ppStyle defaultStyle ---- -- Where defaultStyle = (mode=PageMode, lineLength=80, -- ribbonsPerLine=1.5) pp :: Out a => a -> IO () -- | Semi-customizable pretty printer. -- -- Equivalent to: -- --
-- ppStyle customStyle ---- -- Where customStyle uses the specified line length, 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 Equivalent to: -- --
-- fullPP outputIO (putChar '\n') --ppStyle :: Out a => Style -> a -> IO () -- | The default pretty printer returning Strings -- -- Equivalent to -- --
-- prettyStyle defaultStyle ---- -- Where defaultStyle = (mode=PageMode, lineLength=80, -- ribbonsPerLine=1.5) pretty :: Out a => a -> String -- | Semi-customizable pretty printer. -- -- Equivalent to: -- --
-- prettyStyle customStyle ---- -- Where customStyle uses the specified line length, 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 Equivalent to: -- --
-- fullPP outputStr "" --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 => (TextDetails -> b -> b) -> b -> Style -> a -> b -- | Representable types of kind *. This class is derivable in GHC with the -- XDeriveRepresentable flag on. class Generic a -- | Utility function that handles the text conversion for fullPP. -- -- outputIO transforms the text into Strings and outputs it -- directly. outputIO :: TextDetails -> IO () -> IO () -- | Utility function that handles the text conversion for fullPP. -- -- outputStr just leaves the text as a String which is -- usefull if you want to further process the pretty printed result. outputStr :: TextDetails -> String -> String 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 Bool instance Out a => Out [a] instance Out Double instance Out Float instance Out Int instance Out Char instance Out () 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