The GenericPretty package

[Tags: bsd3, library]

For instance,

data (Eq a) => Constr a = Constr a

will fail because of the (Eq a) context.

The package is installed in the same way as any other package. If needed, instructions are provided below.

0. Make sure you have a version of ghc >= 7.2 installed and that you can use the runhaskell command from the command line.

1. Download the file GenericPretty-1.1.2.tar.gz from this page.

2. Unpack the file. If using a UNIX system, run

tar xzf GenericPretty-1.1.2.tar.gz

If on windows use your preferred unpacking utility(for instance, 7zip : http://www.7-zip.org/)

3. Move to the correct directory:

cd GenericPretty-1.1.2

4. Run the following haskell commands to install the library globally

runhaskell Setup configure

runhaskell Setup build

runhaskell Setup install

If something went wrong, you can check this page for more info, look at manual installation: http://www.haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package

Here is a source file demonstrating the GenericPretty usage

import Text.PrettyPrint.GenericPretty

data Tree a = Leaf a | Node (Tree a) (Tree a) deriving (Generic)

instance (Out a) => Out (Tree a) where docPrec = genOut

tree :: Tree Int

tree = Node (Node (Leaf 333333333) (Leaf (-555555555))) (Leaf 777777777)

main = pp tree

This can be done either directly at the command line, by compiling with ghc -XDeriveGeneric or in the source code by using the LANGUAGE pragma (it seems I can't demonstrate the LANGUAGE pragma since cabal hates special characters. An example however is provided in the README file included in the package). Alternatively, for more information on the LANGUAGE pragma see here: http://www.haskell.org/ghc/docs/7.0.4/html/users_guide/pragmas.html

Besides setting the flag, one must derive Generic for the desired datatype by typing deriving (Generic) and write an instance of Out defining docPrec as docPrec = genOut. Then the pretty printing functions such as pp can be used on any data of that type.

For more details about the above example as well as examples of customizing the pretty printing please check the README file included in the package. For more information about the library itself and what it exports check the API linked further down this page.


Properties

Versions0.1.0, 0.1.1, 0.1.2, 0.1.3, 1.0.0, 1.0.1, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.1.6, 1.1.7, 1.1.8, 1.1.9, 1.2.0, 1.2.1
Dependenciesbase (>=3 && <5), ghc (>=7.2), ghc-prim
LicenseBSD3
AuthorRazvan Ranca
Maintainerranca.razvan@gmail.com
CategoryText, Generics, Pretty Printer
Home pagehttps://github.com/HaggisMcMutton/GenericPretty
Source repositoryhead: git clone git@github.com:HaggisMcMutton/GenericPretty.git
Upload dateThu Aug 11 23:00:09 UTC 2011
Uploaded byRazvanRanca
Downloads1497 total (108 in last 30 days)

Modules

Downloads

Maintainers' corner

For package maintainers and hackage trustees