git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Better let bindings in psci, fix #782
commitd64e06078200ab612735fa156b432967a1afdbbc authorPhil Freeman <paf31@cantab.net> dateTue 10 Feb 2015, 16:46 (12 years ago) parent6be7df9
3 files changed+11−11
psci/Commands.hs+1−1 psci/Main.hs+9−9 psci/Parser.hs+1−1
psci/Commands.hs+1−1
@@ -52,7 +52,7 @@ data Command
5252 -- |
5353 -- Binds a value to a name
5454 --
55− | Let (Expr -> Expr)
55+ | Let [Declaration]
5656 -- |
5757 -- Find the type of an expression
5858 --
psci/Main.hs+9−9
@@ -69,7 +69,7 @@ data PSCiState = PSCiState
6969 { psciImportedFilenames :: [FilePath]
7070 , psciImportedModuleNames :: [P.ModuleName]
7171 , psciLoadedModules :: [(Either P.RebuildPolicy FilePath, P.Module)]
72− , psciLetBindings :: [P.Expr -> P.Expr]
72+ , psciLetBindings :: [P.Declaration]
7373 }
7474
7575-- State helpers
@@ -95,8 +95,8 @@ updateModules modules st = st { psciLoadedModules = psciLoadedModules st ++ modu
9595-- |
9696-- Updates the state to have more let bindings.
9797--
98−updateLets :: (P.Expr -> P.Expr) -> PSCiState -> PSCiState
99−updateLets name st = st { psciLetBindings = name : psciLetBindings st }
98+updateLets :: [P.Declaration] -> PSCiState -> PSCiState
99+updateLets ds st = st { psciLetBindings = ds ++ psciLetBindings st }
100100
101101-- File helpers
102102-- |
@@ -348,13 +348,13 @@ createTemporaryModule exec PSCiState{psciImportedModuleNames = imports, psciLetB
348348 importDecl m = P.ImportDeclaration m P.Unqualified Nothing
349349 traceModule = P.ModuleName [P.ProperName "Debug", P.ProperName "Trace"]
350350 trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
351− itValue = foldl (\x f -> f x) val lets
352351 mainValue = P.App trace (P.Var (P.Qualified Nothing (P.Ident "it")))
353− itDecl = P.ValueDeclaration (P.Ident "it") P.Value [] $ Right itValue
352+ itDecl = P.ValueDeclaration (P.Ident "it") P.Value [] $ Right val
354353 mainDecl = P.ValueDeclaration (P.Ident "main") P.Value [] $ Right mainValue
355354 decls = if exec then [itDecl, mainDecl] else [itDecl]
356355 in
357− P.Module moduleName ((importDecl `map` imports) ++ decls) Nothing
356+ P.Module moduleName ((importDecl `map` imports) ++ lets ++ decls) Nothing
357+
358358
359359-- |
360360-- Makes a volatile module to hold a non-qualified type synonym for a fully-qualified data type declaration.
@@ -408,10 +408,10 @@ handleDeclaration val = do
408408-- Takes a let declaration and updates the environment, then run a make. If the declaration fails,
409409-- restore the pre-let environment.
410410--
411−handleLet :: (P.Expr -> P.Expr) -> PSCI ()
412−handleLet l = do
411+handleLet :: [P.Declaration] -> PSCI ()
412+handleLet ds = do
413413 st <- PSCI $ lift get
414− let st' = updateLets l st
414+ let st' = updateLets ds st
415415 let m = createTemporaryModule False st' (P.ObjectLiteral [])
416416 e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st' ++ [(Left P.RebuildAlways, m)]) []
417417 case e of
psci/Parser.hs+1−1
@@ -76,7 +76,7 @@ parseCommand cmdString =
7676 -- we actually want the normal @let@.
7777 --
7878 psciLet :: P.TokenParser Command
79− psciLet = Let <$> (P.Let <$> (P.reserved "let" *> P.indented *> manyDecls))
79+ psciLet = Let <$> (P.reserved "let" *> P.indented *> manyDecls)
8080 where
8181 manyDecls :: P.TokenParser [P.Declaration]
8282 manyDecls = C.mark (many1 (C.same *> P.parseDeclaration))