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