@@ -13,7 +13,7 @@ import SourceSyntax.Expression
1313import Transform.Substitute
1414
1515
16−toMatch :: [(Pattern, LExpr t v)] -> State Int (String, Match t v)
16+toMatch :: [(Pattern, LExpr)] -> State Int (String, Match)
1717toMatch patterns = do
1818 v <- newVar
1919 (,) v <$> match [v] (map (first (:[])) patterns) Fail
@@ -23,19 +23,19 @@ newVar = do n <- get
2323 modify (+1)
2424 return $ "_v" ++ show n
2525
26−data Match t v
27− = Match String [Clause t v] (Match t v)
26+data Match
27+ = Match String [Clause] Match
2828 | Break
2929 | Fail
30− | Other (LExpr t v)
31− | Seq [Match t v]
30+ | Other LExpr
31+ | Seq [Match]
3232 deriving Show
3333
34−data Clause t v =
35− Clause (Either String Literal) [String] (Match t v)
34+data Clause =
35+ Clause (Either String Literal) [String] Match
3636 deriving Show
3737
38−matchSubst :: [(String,String)] -> Match t v -> Match t v
38+matchSubst :: [(String,String)] -> Match -> Match
3939matchSubst _ Break = Break
4040matchSubst _ Fail = Fail
4141matchSubst pairs (Seq ms) = Seq (map (matchSubst pairs) ms)
@@ -55,7 +55,7 @@ isCon (p:ps, e) =
5555
5656isVar p = not (isCon p)
5757
58−match :: [String] -> [([Pattern],LExpr t v)] -> Match t v -> State Int (Match t v)
58+match :: [String] -> [([Pattern],LExpr)] -> Match -> State Int Match
5959match [] [] def = return def
6060match [] [([],e)] Fail = return $ Other e
6161match [] [([],e)] Break = return $ Other e
@@ -72,7 +72,7 @@ dealias v c@(p:ps, L s e) =
7272 PAlias x pattern -> (pattern:ps, L s $ subst x (Var v) e)
7373 _ -> c
7474
75−matchVar :: [String] -> [([Pattern],LExpr t v)] -> Match t v -> State Int (Match t v)
75+matchVar :: [String] -> [([Pattern],LExpr)] -> Match -> State Int Match
7676matchVar (v:vs) cs def = match vs (map subVar cs) def
7777 where
7878 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
8484 PRecord fs ->
8585 foldr (\x -> subst x (Access (L s (Var v)) x)) e fs
8686
87−matchCon :: [String] -> [([Pattern],LExpr t v)] -> Match t v -> State Int (Match t v)
87+matchCon :: [String] -> [([Pattern],LExpr)] -> Match -> State Int Match
8888matchCon (v:vs) cs def = (flip (Match v) def) <$> mapM toClause css
8989 where
9090 css = groupBy eq (sortBy cmp cs)
@@ -106,9 +106,9 @@ matchCon (v:vs) cs def = (flip (Match v) def) <$> mapM toClause css
106106
107107matchClause :: Either String Literal
108108 -> [String]
109− -> [([Pattern],LExpr t v)]
110− -> Match t v
111− -> State Int (Clause t v)
109+ -> [([Pattern],LExpr)]
110+ -> Match
111+ -> State Int Clause
112112matchClause c (v:vs) cs def =
113113 do vs' <- getVars
114114 Clause c vs' <$> match (vs' ++ vs) (map flatten cs) def
@@ -124,6 +124,6 @@ matchClause c (v:vs) cs def =
124124 (PData _ ps : _, _) -> forM ps (const newVar)
125125 (PLiteral _ : _, _) -> return []
126126
127−matchMix :: [String] -> [([Pattern],LExpr t v)] -> Match t v -> State Int (Match t v)
127+matchMix :: [String] -> [([Pattern],LExpr)] -> Match -> State Int Match
128128matchMix vs cs def = foldM (flip $ match vs) def (reverse css)
129129 where css = groupBy (\p1 p2 -> isCon p1 == isCon p2) cs