@@ -13,7 +13,7 @@ import SourceSyntax.Expression
13import Transform.Substitute
13import Transform.Substitute
16−toMatch :: [(Pattern, LExpr t v)] -> State Int (String, Match t v)
16+toMatch :: [(Pattern, LExpr)] -> State Int (String, Match)
17toMatch patterns = do
17toMatch patterns = do
18 v <- newVar
18 v <- newVar
19 (,) v <$> match [v] (map (first (:[])) patterns) Fail
19 (,) v <$> match [v] (map (first (:[])) patterns) Fail
@@ -23,19 +23,19 @@ newVar = do n <- get
23 modify (+1)
23 modify (+1)
24 return $ "_v" ++ show n
24 return $ "_v" ++ show n
26−data Match t v
26+data Match
27− = Match String [Clause t v] (Match t v)
27+ = Match String [Clause] Match
30− | Other (LExpr t v)
30+ | Other LExpr
31− | Seq [Match t v]
31+ | Seq [Match]
32 deriving Show
32 deriving Show
34−data Clause t v =
34+data Clause =
35− Clause (Either String Literal) [String] (Match t v)
35+ Clause (Either String Literal) [String] Match
36 deriving Show
36 deriving Show
38−matchSubst :: [(String,String)] -> Match t v -> Match t v
38+matchSubst :: [(String,String)] -> Match -> Match
39matchSubst _ Break = Break
39matchSubst _ Break = Break
40matchSubst _ Fail = Fail
40matchSubst _ Fail = Fail
41matchSubst pairs (Seq ms) = Seq (map (matchSubst pairs) ms)
41matchSubst pairs (Seq ms) = Seq (map (matchSubst pairs) ms)
@@ -55,7 +55,7 @@ isCon (p:ps, e) =
56isVar p = not (isCon p)
56isVar p = not (isCon p)
58−match :: [String] -> [([Pattern],LExpr t v)] -> Match t v -> State Int (Match t v)
58+match :: [String] -> [([Pattern],LExpr)] -> Match -> State Int Match
59match [] [] def = return def
59match [] [] def = return def
60match [] [([],e)] Fail = return $ Other e
60match [] [([],e)] Fail = return $ Other e
61match [] [([],e)] Break = return $ Other e
61match [] [([],e)] Break = return $ Other e
@@ -72,7 +72,7 @@ dealias v c@(p:ps, L s e) =
72 PAlias x pattern -> (pattern:ps, L s $ subst x (Var v) e)
72 PAlias x pattern -> (pattern:ps, L s $ subst x (Var v) e)
75−matchVar :: [String] -> [([Pattern],LExpr t v)] -> Match t v -> State Int (Match t v)
75+matchVar :: [String] -> [([Pattern],LExpr)] -> Match -> State Int Match
76matchVar (v:vs) cs def = match vs (map subVar cs) def
76matchVar (v:vs) cs def = match vs (map subVar cs) def
78 subVar (p:ps, ce@(L s e)) = (ps, L s $ subOnePattern p e)
78 subVar (p:ps, ce@(L s e)) = (ps, L s $ subOnePattern p e)
@@ -84,7 +84,7 @@ matchVar (v:vs) cs def = match vs (map subVar cs) def
84 PRecord fs ->
84 PRecord fs ->
85 foldr (\x -> subst x (Access (L s (Var v)) x)) e fs
85 foldr (\x -> subst x (Access (L s (Var v)) x)) e fs
87−matchCon :: [String] -> [([Pattern],LExpr t v)] -> Match t v -> State Int (Match t v)
87+matchCon :: [String] -> [([Pattern],LExpr)] -> Match -> State Int Match
88matchCon (v:vs) cs def = (flip (Match v) def) <$> mapM toClause css
88matchCon (v:vs) cs def = (flip (Match v) def) <$> mapM toClause css
90 css = groupBy eq (sortBy cmp cs)
90 css = groupBy eq (sortBy cmp cs)
@@ -106,9 +106,9 @@ matchCon (v:vs) cs def = (flip (Match v) def) <$> mapM toClause css
107matchClause :: Either String Literal
107matchClause :: Either String Literal
108 -> [String]
108 -> [String]
109− -> [([Pattern],LExpr t v)]
109+ -> [([Pattern],LExpr)]
110− -> Match t v
110+ -> Match
111− -> State Int (Clause t v)
111+ -> State Int Clause
112matchClause c (v:vs) cs def =
112matchClause c (v:vs) cs def =
113 do vs' <- getVars
113 do vs' <- getVars
114 Clause c vs' <$> match (vs' ++ vs) (map flatten cs) def
114 Clause c vs' <$> match (vs' ++ vs) (map flatten cs) def
@@ -124,6 +124,6 @@ matchClause c (v:vs) cs def =
124 (PData _ ps : _, _) -> forM ps (const newVar)
124 (PData _ ps : _, _) -> forM ps (const newVar)
125 (PLiteral _ : _, _) -> return []
125 (PLiteral _ : _, _) -> return []
127−matchMix :: [String] -> [([Pattern],LExpr t v)] -> Match t v -> State Int (Match t v)
127+matchMix :: [String] -> [([Pattern],LExpr)] -> Match -> State Int Match
128matchMix vs cs def = foldM (flip $ match vs) def (reverse css)
128matchMix vs cs def = foldM (flip $ match vs) def (reverse css)
129 where css = groupBy (\p1 p2 -> isCon p1 == isCon p2) cs
129 where css = groupBy (\p1 p2 -> isCon p1 == isCon p2) cs