@@ -73,24 +73,26 @@ plist = foldr pcons pnil
7373ptuple es = PData ("Tuple" ++ show (length es)) es
7474
7575brkt s = "{ " ++ s ++ " }"
76+parensIf b s = if b then parens s else s
7677
7778instance Show Pattern where
78− show (PRecord fs) = brkt (intercalate ", " fs)
79− show (PVar x) = x
80− show PAnything = "_"
81− show (PData "Cons" [hd@(PData "Cons" _),tl]) =
82− parens (show hd) ++ " : " ++ show tl
83− where parens s = "(" ++ s ++ ")"
84− show (PData "Cons" [hd,tl]) = show hd ++ " : " ++ show tl
85− show (PData "Nil" []) = "[]"
86− show (PData name ps) =
79+ show p =
80+ case p of
81+ PRecord fs -> brkt (intercalate ", " fs)
82+ PVar x -> x
83+ PAnything -> "_"
84+ PData "Cons" [hd@(PData "Cons" _),tl] ->
85+ parens (show hd) ++ " :: " ++ show tl
86+ PData "Cons" [hd,tl] -> show hd ++ " : " ++ show tl
87+ PData "Nil" [] -> "[]"
88+ PData name ps ->
8789 if take 5 name == "Tuple" && all isDigit (drop 5 name) then
8890 parens . intercalate ", " $ map show ps
89− else (if null ps then id else parens) $ unwords (name : map show ps)
90− where parens s = "(" ++ s ++ ")"
91+ else parensIf (not (null ps)) $ unwords (name : map show ps)
9192
9293instance Show Expr where
9394 show e =
95+ let show' (C _ _ e) = parensIf (needsParens e) (show e) in
9496 case e of
9597 IntNum n -> show n
9698 FloatNum n -> show n
@@ -138,13 +140,13 @@ getLambdas (C _ _ (Lambda x e)) = (x:xs,e')
138140 where (xs,e') = getLambdas e
139141getLambdas e = ([],e)
140142
141−show' (C _ _ e) = if needsParens e then "(" ++ show e ++ ")" else show e
142−
143−needsParens (Binop _ _ _) = True
144−needsParens (Lambda _ _) = True
145−needsParens (App _ _) = True
146−needsParens (If _ _ _) = True
147−needsParens (Let _ _) = True
148−needsParens (Case _ _) = True
149−needsParens (Data name (x:xs)) = name /= "Cons"
150−needsParens _ = False
143+needsParens e =
144+ case e of
145+ Binop _ _ _ -> True
146+ Lambda _ _ -> True
147+ App _ _ -> True
148+ If _ _ _ -> True
149+ Let _ _ -> True
150+ Case _ _ -> True
151+ Data name (x:xs) -> name /= "Cons"
152+ _ -> False