on d66da21 help sign in
Idris-dev/src/Util/Pretty.hs
33 lines 723 B history raw
1module Util.Pretty (
2 module Text.PrettyPrint.HughesPJ,
3 Sized(..), breakingSize, nestingSize,
4 Pretty(..)
5) where
7import Text.PrettyPrint.HughesPJ
9-- A rough notion of size for pretty printing various types.
10class Sized a where
11 size :: a -> Int
13instance (Sized a, Sized b) => Sized (a, b) where
14 size (left, right) = 1 + size left + size right
16instance Sized a => Sized [a] where
17 size = sum . map size
19-- The maximum size before we break on to another line.
20breakingSize :: Int
21breakingSize = 15
23nestingSize :: Int
24nestingSize = 1
26class Pretty a where
27 pretty :: a -> Doc
29instance Pretty () where
30 pretty () = text "()"
32instance Pretty a => Pretty [a] where
33 pretty l = foldr ($$) empty $ map pretty l