https://github.com/nwtgck/hindent-show
Pretty printing by hindent
https://github.com/nwtgck/hindent-show
haskell haskell-library haskell-stack pretty-print
Last synced: 3 months ago
JSON representation
Pretty printing by hindent
- Host: GitHub
- URL: https://github.com/nwtgck/hindent-show
- Owner: nwtgck
- License: bsd-3-clause
- Created: 2018-05-13T07:40:29.000Z (about 7 years ago)
- Default Branch: develop
- Last Pushed: 2018-05-14T12:24:24.000Z (about 7 years ago)
- Last Synced: 2024-10-11T15:11:36.774Z (9 months ago)
- Topics: haskell, haskell-library, haskell-stack, pretty-print
- Language: Haskell
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# hindent-show
[](https://travis-ci.com/nwtgck/hindent-show)Pretty printing by hindent
## Install
Add this library to your `stack.yaml` like the following if you use [Stack](https://docs.haskellstack.org/en/stable/README/).
```yaml
...
extra-deps:
- git: https://github.com/nwtgck/hindent-show.git
commit: 7b3c1fa21f7fac8f124361d1ab8fdaf0155a1445
...
```Then, add `hindent-show` to your `package.yaml`.
```yaml
...
library:
dependencies:
- hindent-show
...
```## Usage - pretty-print a data structure
Here is an example to pretty-print a tree.
```hs
data Tree a
= Node { value :: a
, left :: (Tree a)
, right :: (Tree a) }
| Leaf
deriving (Show)main :: IO
main = do
let tree1 = Node 1 (Node 2 Leaf (Node 1 (Node 2 Leaf Leaf) Leaf)) (Node 1 (Node 2 Leaf Leaf) Leaf)
hindentPrint tree1
```### output
```txt
Node
{ value = 1
, left =
Node
{ value = 2
, left = Leaf
, right =
Node
{ value = 1
, left = Node {value = 2, left = Leaf, right = Leaf}
, right = Leaf
}
}
, right =
Node
{ value = 1
, left = Node {value = 2, left = Leaf, right = Leaf}
, right = Leaf
}
}
```## Usage - indent of code
```hs
main :: IO ()
main = do
let formated :: String
formated = hidentFormat "a = [332521132,20783,30,4093902,1390,109301,93132,3901,83912,218491,284913]"
putStrLn formated```
### output
```
a =
[ 332521132
, 20783
, 30
, 4093902
, 1390
, 109301
, 93132
, 3901
, 83912
, 218491
, 284913
]
```