@@ -4,10 +4,10 @@ module Transform.Substitute (subst) where
44import Control.Arrow (second, (***))
55import SourceSyntax.Expression
66import SourceSyntax.Location
7+import qualified SourceSyntax.Pattern as Pattern
78import qualified Data.Set as Set
8−import qualified Transform.SortDefinitions as SD
99
10−subst :: String -> Expr t v -> Expr t v -> Expr t v
10+subst :: String -> Expr -> Expr -> Expr
1111subst old new expr =
1212 let f (L s e) = L s (subst old new e) in
1313 case expr of
@@ -15,7 +15,7 @@ subst old new expr =
1515 ExplicitList es -> ExplicitList (map f es)
1616 Binop op e1 e2 -> Binop op (f e1) (f e2)
1717 Lambda p e
18− | Set.member old (SD.boundVars p) -> expr
18+ | Set.member old (Pattern.boundVars p) -> expr
1919 | otherwise -> Lambda p (f e)
2020 App e1 e2 -> App (f e1) (f e2)
2121 MultiIf ps -> MultiIf (map (f *** f) ps)
@@ -24,12 +24,9 @@ subst old new expr =
2424 | anyShadow -> expr
2525 | otherwise -> Let (map substDef defs) (f body)
2626 where
27+ substDef (Definition p e t) = Definition p (f e) t
2728 anyShadow =
28− any (Set.member old . SD.boundVars) [ p | Def p _ <- defs ]
29− substDef def =
30− case def of
31− TypeAnnotation _ _ -> def
32− Def p e -> Def p (f e)
29+ any (Set.member old . Pattern.boundVars) [ p | Definition p _ _ <- defs ]
3330
3431 Var x -> if x == old then new else expr
3532 Case e cases -> Case (f e) $ map (second f) cases