GenericPretty
Memo
Show と同等の Out という型クラスが定義されている
整形方法もカスタマイズ可能
使い方
{-# LANGUAGE DeriveGeneric #-}
import Text.PrettyPrint.GenericPretty
data Tree a
= Leaf a
| Fork (Tree a) (Tree a)
deriving (Generic)
instance (Out a) => Out (Tree a)
t1, t2, t3, t4, t5 :: Tree Int
t5 = Fork t4 t4
t4 = Fork t3 t3
t3 = Fork t2 t2
t2 = Fork t1 t1
t1 = Fork t0 t0
t0 = Fork (Leaf 1) (Leaf 2)
λ stack repl --package GenericPretty
> :l Main.hs
> pp t1
Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2))
> pp t2
Fork (Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
(Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
> pp t3
Fork (Fork (Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
(Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2))))
(Fork (Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
(Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2))))
> pp t4
Fork (Fork (Fork (Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
(Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2))))
(Fork (Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
(Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))))
(Fork (Fork (Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
(Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2))))
(Fork (Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
(Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))))
> pp t5
Fork (Fork (Fork (Fork (Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
(Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2))))
(Fork (Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
(Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))))
(Fork (Fork (Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
(Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2))))
(Fork (Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
(Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2))))))
(Fork (Fork (Fork (Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
(Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2))))
(Fork (Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
(Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))))
(Fork (Fork (Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
(Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2))))
(Fork (Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2)))
(Fork (Fork (Leaf 1) (Leaf 2))
(Fork (Leaf 1) (Leaf 2))))))
リソース
Last updated