-
Notifications
You must be signed in to change notification settings - Fork 8
/
Display.hs
46 lines (30 loc) · 1.31 KB
/
Display.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{-# LANGUAGE PackageImports, GADTs, KindSignatures, StandaloneDeriving, EmptyDataDecls, FlexibleInstances, OverloadedStrings #-}
module Display (Pretty(..), Doc, ($$), (<+>), text, hang, vcat, parensIf, sep, comma, nest, parens,
subscriptPretty, superscriptPretty, subscriptShow, render, punctuate) where
import GHC.Exts( IsString(..) )
import Prelude hiding (length, reverse)
import Text.PrettyPrint.HughesPJ
import Numeric (showIntAtBase)
import Control.Arrow (second)
import Control.Monad.Error
import Data.Sequence hiding (empty)
import Data.Foldable
class Pretty a where
pretty :: a -> Doc
instance Pretty x => Pretty [x] where
pretty x = brackets $ sep $ punctuate comma (map pretty x)
instance Pretty Int where
pretty = int
instance Pretty Bool where
pretty = text . show
scriptPretty :: String -> Int -> Doc
scriptPretty s = text . scriptShow s
scriptShow (minus:digits) x = if x < 0 then minus : sho (negate x) else sho x
where sho x = showIntAtBase 10 (\i -> digits !! i) x []
superscriptPretty = scriptPretty "⁻⁰¹²³⁴⁵⁶⁷⁸⁹"
subscriptPretty = scriptPretty "-₀₁₂₃₄₅₆₇₈₉"
subscriptShow :: Int -> String
subscriptShow = scriptShow "-₀₁₂₃₄₅₆₇₈₉"
parensIf :: Bool -> Doc -> Doc
parensIf True = parens
parensIf False = id