项目作者: nwtgck

项目描述 :
Pretty printing by hindent
高级语言: Haskell
项目地址: git://github.com/nwtgck/hindent-show.git
创建时间: 2018-05-13T07:40:29Z
项目社区:https://github.com/nwtgck/hindent-show

开源协议:Other

下载


hindent-show

Build Status

Pretty printing by hindent

Install

Add this library to your stack.yaml like the following if you use Stack.

  1. ...
  2. extra-deps:
  3. - git: https://github.com/nwtgck/hindent-show.git
  4. commit: 7b3c1fa21f7fac8f124361d1ab8fdaf0155a1445
  5. ...

Then, add hindent-show to your package.yaml.

  1. ...
  2. library:
  3. dependencies:
  4. - hindent-show
  5. ...

Usage - pretty-print a data structure

Here is an example to pretty-print a tree.

  1. data Tree a
  2. = Node { value :: a
  3. , left :: (Tree a)
  4. , right :: (Tree a) }
  5. | Leaf
  6. deriving (Show)
  7. main :: IO
  8. main = do
  9. let tree1 = Node 1 (Node 2 Leaf (Node 1 (Node 2 Leaf Leaf) Leaf)) (Node 1 (Node 2 Leaf Leaf) Leaf)
  10. hindentPrint tree1

output

  1. Node
  2. { value = 1
  3. , left =
  4. Node
  5. { value = 2
  6. , left = Leaf
  7. , right =
  8. Node
  9. { value = 1
  10. , left = Node {value = 2, left = Leaf, right = Leaf}
  11. , right = Leaf
  12. }
  13. }
  14. , right =
  15. Node
  16. { value = 1
  17. , left = Node {value = 2, left = Leaf, right = Leaf}
  18. , right = Leaf
  19. }
  20. }

Usage - indent of code

  1. main :: IO ()
  2. main = do
  3. let formated :: String
  4. formated = hidentFormat "a = [332521132,20783,30,4093902,1390,109301,93132,3901,83912,218491,284913]"
  5. putStrLn formated

output

  1. a =
  2. [ 332521132
  3. , 20783
  4. , 30
  5. , 4093902
  6. , 1390
  7. , 109301
  8. , 93132
  9. , 3901
  10. , 83912
  11. , 218491
  12. , 284913
  13. ]