https://hackage.haskell.org/package/PPrinter
- Go to the directory of ./src.
- Using the command 'cabal configure' and then 'cabal install'
Please check the official instructions for Haskell.
- Open a new Haskell file and adding the pragma 'DeriveGeneric'
- Adding the line 'import Text.PPrinter'.
- Define a new type by following the steps below:
i. Define a data type with deriving mechanism at first:
data Tree = Node String [Tree] deriving (Generic, Show)
You should add ‘deriving (Generic, Show)’ in the end, both of ‘Generic’ and ‘Show’ are necessary.
ii. Define an EMPTY Pretty instance of the data type:
instance Pretty (Tree)
iii. Define the exact data of the type:
tree = Node "aaa" [
Node "bbbbb" [
Node "ccc" [],
Node "dd" []
],
Node "eee" [],
Node "ffff" [
Node "gg" [],
Node "hhh" [],
Node "ii" []
]
]
iv. Output the data by the builtin functions:
$ pprint tree
$ Node "aaa"
[Node "bbbbb"
[Node "ccc" [],
Node "dd" []],
Node "eee" [],
Node "ffff"
[Node "gg" [],
Node "hhh" [],
Node "ii" []]]