@@ -13,7 +13,6 @@ import qualified SourceSyntax.Pattern as P
1313import qualified SourceSyntax.Variable as V
1414import Transform.Substitute
1515
16−
1716toMatch :: [(P.Pattern, Expr)] -> State Int (String, Match)
1817toMatch patterns = do
1918 v <- newVar
@@ -37,16 +36,19 @@ data Clause =
3736 deriving Show
3837
3938matchSubst :: [(String,String)] -> Match -> Match
40−matchSubst _ Break = Break
41−matchSubst _ Fail = Fail
42−matchSubst pairs (Seq ms) = Seq (map (matchSubst pairs) ms)
43−matchSubst pairs (Other (A a e)) =
44− Other . A a $ foldr ($) e $ map (\(x,y) -> subst x (rawVar y)) pairs
45−matchSubst pairs (Match n cs m) =
46− Match (varSubst n) (map clauseSubst cs) (matchSubst pairs m)
47− where varSubst v = fromMaybe v (lookup v pairs)
48− clauseSubst (Clause c vs m) =
49− Clause c (map varSubst vs) (matchSubst pairs m)
39+matchSubst pairs match =
40+ case match of
41+ Break -> Break
42+ Fail -> Fail
43+ Seq ms -> Seq (map (matchSubst pairs) ms)
44+ Other (A a e) ->
45+ Other . A a $ foldr ($) e $ map (\(x,y) -> subst x (rawVar y)) pairs
46+ Match n cs m ->
47+ Match (varSubst n) (map clauseSubst cs) (matchSubst pairs m)
48+ where
49+ varSubst v = fromMaybe v (lookup v pairs)
50+ clauseSubst (Clause c vs m) =
51+ Clause c (map varSubst vs) (matchSubst pairs m)
5052
5153isCon (p:_, _) =
5254 case p of
@@ -68,6 +70,7 @@ match vs@(v:_) cs def
6870 where
6971 cs' = map (dealias v) cs
7072
73+dealias :: String -> ([P.Pattern],Expr) -> ([P.Pattern],Expr)
7174dealias v c@(p:ps, A a e) =
7275 case p of
7376 P.Alias x pattern -> (pattern:ps, A a $ subst x (rawVar v) e)