on master help sign in
Add variable renaming for new Let representation.
commit848f31c4b73e55a45b93503eb1ca50b77842ddce authorevancz <info@elm-lang.org> dateSat 28 Jul 2012, 20:46 (14 years ago) parent45f834e
1 file changed+11−4
elm/src/Rename.hs+11−4
elm/src/Rename.hs+11−4
@@ -3,7 +3,7 @@ module Rename (rename) where
33
44import Ast
55import Control.Arrow (first)
6−import Control.Monad (ap, liftM, foldM, mapM, Monad)
6+import Control.Monad (ap, liftM, foldM, mapM, Monad, zipWithM)
77import Control.Monad.State (evalState, State, get, put)
88import Data.Char (isLower)
99import Guid
@@ -50,9 +50,13 @@ rename' env expr =
5050
5151 Let defs e ->
5252 let (fs,argss,es) = unzip3 $ map (\(Definition a b c) -> (a,b,c)) defs in
53− do env' <- foldM (\acc x -> snd `liftM` extend acc x) env fs
54− es' <- mapM (rename' env') es; re <- rename' env' e
55− return $ Let (zipWith3 Definition (map env' fs) argss es') re
53+ do env' <- extends env fs
54+ let combine args e = do env'' <- extends env' args
55+ re <- rename' env'' e
56+ return (map env'' args, re)
57+ defs' <- zipWith (\f -> uncurry $ Definition f) (map env' fs) `liftM` zipWithM combine argss es
58+ re <- rename' env' e
59+ return $ Let defs' re
5660
5761 Var x -> return . Var $ env x
5862
@@ -71,6 +75,9 @@ extend env x = do
7175 let rx = map (\c -> if c == '\'' then '_' else c) $ x ++ "_" ++ show n
7276 return (rx, \y -> if y == x then rx else env y)
7377
78+extends :: (String -> String) -> [String] -> GuidCounter (String -> String)
79+extends env xs = foldM (\e x -> liftM snd $ extend e x) env xs
80+
7481patternExtend :: Pattern -> (String -> String) -> GuidCounter (Pattern, String -> String)
7582patternExtend pattern env =
7683 case pattern of