@@ -1,4 +1,4 @@
1−module Generate.Cases (caseToMatch, Match (..), Clause (..), matchSubst) where
1+module Generate.Cases (caseToMatch, Match (..), Clause (..), matchSubst, deprime) where
3import Control.Arrow (first)
3import Control.Arrow (first)
4import Control.Monad (liftM,foldM)
4import Control.Monad (liftM,foldM)
@@ -12,6 +12,9 @@ import SourceSyntax.Pattern
12import SourceSyntax.Expression
12import SourceSyntax.Expression
13import Transform.Substitute
13import Transform.Substitute
15+deprime :: String -> String
16+deprime = map (\c -> if c == '\'' then '$' else c)
15caseToMatch patterns = do
18caseToMatch patterns = do
16 v <- newVar
19 v <- newVar
17 (,) v `liftM` match [v] (map (first (:[])) patterns) Fail
20 (,) v `liftM` match [v] (map (first (:[])) patterns) Fail
@@ -65,7 +68,7 @@ match vs@(v:_) cs def
66dealias v c@(p:ps, L s e) =
69dealias v c@(p:ps, L s e) =
68− PAlias x pattern -> (pattern:ps, L s $ subst x (Var v) e)
71+ PAlias x pattern -> (pattern:ps, L s $ subst (deprime x) (Var v) e)
71matchVar :: [String] -> [([Pattern],LExpr t v)] -> Match t v
74matchVar :: [String] -> [([Pattern],LExpr t v)] -> Match t v
@@ -76,7 +79,7 @@ matchVar (v:vs) cs def = match vs (map subVar cs) def
77 subOnePattern pattern e =
80 subOnePattern pattern e =
78 case pattern of
81 case pattern of
79− PVar x -> subst x (Var v) e
82+ PVar x -> subst (deprime x) (Var v) e
80 PAnything -> e
83 PAnything -> e
81 PRecord fs ->
84 PRecord fs ->
82 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