@@ -4,10 +4,10 @@ module Transform.Substitute (subst) where
4import Control.Arrow (second, (***))
4import Control.Arrow (second, (***))
5import SourceSyntax.Expression
5import SourceSyntax.Expression
6import SourceSyntax.Location
6import SourceSyntax.Location
7+import qualified SourceSyntax.Pattern as Pattern
7import qualified Data.Set as Set
8import qualified Data.Set as Set
8−import qualified Transform.SortDefinitions as SD
10−subst :: String -> Expr t v -> Expr t v -> Expr t v
10+subst :: String -> Expr -> Expr -> Expr
11subst old new expr =
11subst old new expr =
12 let f (L s e) = L s (subst old new e) in
12 let f (L s e) = L s (subst old new e) in
13 case expr of
13 case expr of
@@ -15,7 +15,7 @@ subst old new expr =
15 ExplicitList es -> ExplicitList (map f es)
15 ExplicitList es -> ExplicitList (map f es)
16 Binop op e1 e2 -> Binop op (f e1) (f e2)
16 Binop op e1 e2 -> Binop op (f e1) (f e2)
17 Lambda p e
17 Lambda p e
18− | Set.member old (SD.boundVars p) -> expr
18+ | Set.member old (Pattern.boundVars p) -> expr
19 | otherwise -> Lambda p (f e)
19 | otherwise -> Lambda p (f e)
20 App e1 e2 -> App (f e1) (f e2)
20 App e1 e2 -> App (f e1) (f e2)
21 MultiIf ps -> MultiIf (map (f *** f) ps)
21 MultiIf ps -> MultiIf (map (f *** f) ps)
@@ -24,12 +24,9 @@ subst old new expr =
24 | anyShadow -> expr
24 | anyShadow -> expr
25 | otherwise -> Let (map substDef defs) (f body)
25 | otherwise -> Let (map substDef defs) (f body)
27+ substDef (Definition p e t) = Definition p (f e) t
27 anyShadow =
28 anyShadow =
28− any (Set.member old . SD.boundVars) [ p | Def p _ <- defs ]
29+ any (Set.member old . Pattern.boundVars) [ p | Definition p _ _ <- defs ]
31− TypeAnnotation _ _ -> def
32− Def p e -> Def p (f e)
34 Var x -> if x == old then new else expr
31 Var x -> if x == old then new else expr
35 Case e cases -> Case (f e) $ map (second f) cases
32 Case e cases -> Case (f e) $ map (second f) cases