fp-il

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 5ded005cb6dab79c96e84e67ba6f4f7eddda17d6
parent 07c38414dc9816b56d27a3d86b856ffe23caff11
Author: Erik Oosting <crazazy@tilde.cafe>
Date:   Wed, 31 Jan 2024 18:02:42 +0100

made a proper version of CExp substitution

Diffstat:
Mhaskell/app/Lift.hs | 20+++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/haskell/app/Lift.hs b/haskell/app/Lift.hs @@ -95,11 +95,12 @@ subVarsAExp (env, rest) = fmap (env,) rest subVarsCExp :: ([String], [String], CExpF a) -> CExpF ([String], [String], a) subVarsCExp (env, queue, LetF name fc rest) = let - (newName, newFC) = + (newName, oldNames) = foldr - (\m (n, f) -> if n == m then (n ++ "_", replaceVarsFC n f) else (n, f)) -- repeatedly replace variables in the function call - (name, fc) + (\m (n, ns) -> if n == m then (n ++ "_", n:ns) else (n, ns)) -- repeatedly replace variables in the function call + (name, []) queue -- make sure to do oldest first! + newFC = foldr replaceVarsFC fc $ oldNames \\ [newName] in LetF newName newFC (if name `elem` env then (env, newName : queue, rest) else (name : env, name : queue, rest)) subVarsCExp (env, queue, IfF cond thenPart elsePart) = @@ -108,3 +109,16 @@ subVarsCExp (env, queue, IfF cond thenPart elsePart) = (env, queue, thenPart) (env, queue, elsePart) subVarsCExp (env, queue, FCF fc) = FCF $ foldr replaceVarsFC fc queue + + +unsafeCotransverse n = ana (n . fmap project) + +subVarsCExp' (env, LetF name fc body) + | name `elem` env = + let + newName = name ++ "_" + newFC = replaceVarsFC newName fc + newBody = cata replaceVarsCExp body name + in LetF newName newFC (newName : env, newBody) + | otherwise = LetF name fc (name : env, body) +subVarsCExp' (env, rest) = fmap (env,) rest