@@ -15,25 +15,24 @@ data Expr t v
15 = Literal Literal.Literal
15 = Literal Literal.Literal
16 | Var String
16 | Var String
17 | Range (LExpr t v) (LExpr t v)
17 | Range (LExpr t v) (LExpr t v)
18− | Access (LExpr t v) String
18+ | ExplicitList [LExpr t v]
19− | Remove (LExpr t v) String
20− | Insert (LExpr t v) String (LExpr t v)
21− | Modify (LExpr t v) [(String, LExpr t v)]
22− | Record [(String, [String], LExpr t v)]
23 | Binop String (LExpr t v) (LExpr t v)
19 | Binop String (LExpr t v) (LExpr t v)
24− | Lambda String (LExpr t v)
20+ | Lambda Pattern.Pattern (LExpr t v)
25 | App (LExpr t v) (LExpr t v)
21 | App (LExpr t v) (LExpr t v)
26 | MultiIf [(LExpr t v,LExpr t v)]
22 | MultiIf [(LExpr t v,LExpr t v)]
27 | Let [Def t v] (LExpr t v)
23 | Let [Def t v] (LExpr t v)
28 | Case (LExpr t v) [(Pattern.Pattern, LExpr t v)]
24 | Case (LExpr t v) [(Pattern.Pattern, LExpr t v)]
29− | ExplicitList [LExpr t v]
30 | Data String [LExpr t v]
25 | Data String [LExpr t v]
26+ | Access (LExpr t v) String
27+ | Remove (LExpr t v) String
28+ | Insert (LExpr t v) String (LExpr t v)
29+ | Modify (LExpr t v) [(String, LExpr t v)]
30+ | Record [(String, [String], LExpr t v)] -- [Def t v]
31 | Markdown Pandoc.Pandoc
31 | Markdown Pandoc.Pandoc
32 deriving (Eq, Data, Typeable)
32 deriving (Eq, Data, Typeable)
34data Def tipe var
34data Def tipe var
35− = FnDef String [String] (LExpr tipe var)
35+ = Def String [String] (LExpr tipe var)
36− | OpDef String String String (LExpr tipe var)
37 | TypeAnnotation String Type
36 | TypeAnnotation String Type
38 deriving (Eq, Data, Typeable)
37 deriving (Eq, Data, Typeable)
@@ -49,15 +48,7 @@ instance Show (Expr t v) where
50 Literal lit -> show lit
49 Literal lit -> show lit
51 Range e1 e2 -> "[" ++ show e1 ++ ".." ++ show e2 ++ "]"
50 Range e1 e2 -> "[" ++ show e1 ++ ".." ++ show e2 ++ "]"
52− Access e x -> show' e ++ "." ++ x
51+ ExplicitList es -> "[" ++ intercalate "," (map show es) ++ "]"
53− Remove e x -> Help.brkt (show e ++ " - " ++ x)
54− Insert (Location.L _ _ (Remove e y)) x v ->
55− Help.brkt (show e ++ " - " ++ y ++ " | " ++ x ++ " = " ++ show v)
56− Insert e x v -> Help.brkt (show e ++ " | " ++ x ++ " = " ++ show v)
57− Modify e fs -> Help.brkt (show e ++" | "++ intercalate ", " (map field fs))
58− where field (x,e) = x ++ " <- " ++ show e
59− Record r -> Help.brkt (intercalate ", " (map fields r))
60− where fields (f,args,e) = f ++ concatMap (' ':) args ++ " = " ++ show e
61 Binop op e1 e2 -> show' e1 ++ " " ++ op ++ " " ++ show' e2
52 Binop op e1 e2 -> show' e1 ++ " " ++ op ++ " " ++ show' e2
62 Lambda x e -> let (xs,e') = getLambdas (Location.none $ Lambda x e) in
53 Lambda x e -> let (xs,e') = getLambdas (Location.none $ Lambda x e) in
63 concat [ "\\", intercalate " " xs, " -> ", show e' ]
54 concat [ "\\", intercalate " " xs, " -> ", show e' ]
@@ -69,22 +60,34 @@ instance Show (Expr t v) where
69 Var (c:cs) -> if Help.isOp c then Help.parens (c:cs) else c:cs
60 Var (c:cs) -> if Help.isOp c then Help.parens (c:cs) else c:cs
70 Case e pats -> "case "++ show e ++" of " ++ Help.brkt (intercalate " ; " pats')
61 Case e pats -> "case "++ show e ++" of " ++ Help.brkt (intercalate " ; " pats')
71 where pats' = map (\(p,e) -> show p ++ " -> " ++ show e) pats
62 where pats' = map (\(p,e) -> show p ++ " -> " ++ show e) pats
72− ExplicitList es -> "[" ++ intercalate "," (map show es) ++ "]"
73 Data "::" [h,t] -> show h ++ " :: " ++ show t
63 Data "::" [h,t] -> show h ++ " :: " ++ show t
74 Data "[]" [] -> "[]"
64 Data "[]" [] -> "[]"
75 Data name es -> name ++ " " ++ intercalate " " (map show' es)
65 Data name es -> name ++ " " ++ intercalate " " (map show' es)
66+ Access e x -> show' e ++ "." ++ x
67+ Remove e x -> Help.brkt (show e ++ " - " ++ x)
68+ Insert (Location.L _ _ (Remove e y)) x v ->
69+ Help.brkt (show e ++ " - " ++ y ++ " | " ++ x ++ " = " ++ show v)
70+ Insert e x v -> Help.brkt (show e ++ " | " ++ x ++ " = " ++ show v)
71+ Modify e fs -> Help.brkt (show e ++" | "++ intercalate ", " (map field fs))
72+ where field (x,e) = x ++ " <- " ++ show e
73+ Record r -> Help.brkt (intercalate ", " (map fields r))
74+ where fields (f,args,e) = f ++ concatMap (' ':) args ++ " = " ++ show e
76 Markdown _ -> "[markdown| ... |]"
75 Markdown _ -> "[markdown| ... |]"
79instance Show (Def t v) where
78instance Show (Def t v) where
82− FnDef v [] e -> v ++ " = " ++ show e
83− FnDef f args e -> f ++ concatMap (' ':) args ++ " = " ++ show e
84− OpDef op a1 a2 e -> intercalate " " [a1,op,a2] ++ " = " ++ show e
85 TypeAnnotation n t -> n ++ " : " ++ show t
81 TypeAnnotation n t -> n ++ " : " ++ show t
82+ Def name@(c:_) args e ->
83+ value ++ " = " ++ show e
85+ value = if not (Help.isOp c) then name ++ concatMap (' ':) args else
88+ [a,b] -> a ++ " " ++ name ++ " " ++ b
87−getLambdas (Location.L _ _ (Lambda x e)) = (x:xs,e')
90+getLambdas (Location.L _ _ (Lambda x e)) = (show x:xs,e')
88 where (xs,e') = getLambdas e
91 where (xs,e') = getLambdas e
89getLambdas e = ([],e)
92getLambdas e = ([],e)