---------------------------------------------------------------------- > module Print ( Pretty.. > ) > where ----------------------------------------------------------------------
---------------------------------------------------------------------- > import Support ( replicate ) > > import Pretty > > import Expr ( Prim(..), Expr(..) ) > import Limes ( Extended(..) ) ----------------------------------------------------------------------
---------------------------------------------------------------------- > instance Pretty Prim where > ppPrec _ f = str (case f of > Sin -> "sin"; Cos -> "cos"; > Tan -> "tan"; Cot -> "cot"; > Exp -> "exp"; Ln -> "ln"; > Log -> "log"; > Arcsin -> "arcsin"; Arccos -> "arccos"; > Arctan -> "arctan"; Arccot -> "arccot"; > Sinh -> "sinh"; Cosh -> "cosh"; > Tanh -> "tanh"; Coth -> "coth"; > Abs -> "abs") ----------------------------------------------------------------------
---------------------------------------------------------------------- > instance Pretty Expr where > ppPrec _ (Var x) = str x > ppPrec d (Lit (m :% n)) > | n == 1 && m >= 0 = ppShow m > | n == 1 = paren (d > 4) [ppShow m] > | otherwise = paren (d > 3) > [ppShow m, str "/", ppShow n] > ppPrec d (AppPrim f n e) = paren (d > 9) > [pp f, str (replicate n '\"), char ' ', ppPrec 9 e] > ppPrec d (AppFun f n e) = paren (d > 9) > [str f, str (replicate n '\"), char ' ', ppPrec 9 e] > ppPrec d (Neg e) = paren (d > 4) > [str " -", brk 1, ppPrec 5 e] > ppPrec d (Add e1 e2) = paren (d > 2) > [ppPrec 2 e1, str " +", brk 1, ppPrec 2 e2] > ppPrec d (Sub e1 e2) = paren (d > 2) > [ppPrec 2 e1, str " -", brk 1, ppPrec 3 e2] > ppPrec d (Mul e1 e2) = paren (d > 3) > [ppPrec 3 e1, str " *", brk 1, ppPrec 3 e2] > ppPrec d (Div e1 e2) = paren (d > 3) > [ppPrec 4 e1, str " /", brk 1, ppPrec 4 e2] > ppPrec d (Pow e1 e2) = paren (d > 5) > [ppPrec 6 e1, str "^", ppPrec 5 e2] ----------------------------------------------------------------------
----------------------------------------------------------------------
> paren True ts = sequ [char '(', block 0 ts, char ')']
> paren False ts = sequ ts
----------------------------------------------------------------------
---------------------------------------------------------------------- > instance Pretty a => Pretty (Extended a) where > ppPrec _ MInfty = str "-oo" > ppPrec d (Proper v) = ppPrec d v > ppPrec _ Infty = str "oo" ----------------------------------------------------------------------
Go to the first, previous, next, last section, table of contents.