@@ -233,6 +233,14 @@ instance P.MonadMake Make where
233mkdirp :: FilePath -> IO ()
233mkdirp :: FilePath -> IO ()
234mkdirp = createDirectoryIfMissing True . takeDirectory
234mkdirp = createDirectoryIfMissing True . takeDirectory
237+-- Just an empty module.
239+emptyModule :: P.Module
241+ let moduleName = P.ModuleName [P.ProperName "$PSCI"]
242+ in P.Module moduleName [] Nothing
237-- Makes a volatile module to execute the current expression.
245-- Makes a volatile module to execute the current expression.
@@ -288,6 +296,19 @@ handleDeclaration value = do
288 Just (ExitFailure _, _, err) -> PSCI $ outputStrLn err
296 Just (ExitFailure _, _, err) -> PSCI $ outputStrLn err
289 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
297 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
300+-- Imports a module, preserving the initial state on failure.
302+handleImport :: P.ModuleName -> PSCI ()
303+handleImport moduleName = do
304+ s <- liftM (updateImports moduleName) $ PSCI $ lift get
305+ e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules s ++ [("$PSCI.purs", emptyModule)]) []
307+ Left err -> PSCI $ outputStrLn err
292-- Takes a value and prints its type
313-- Takes a value and prints its type
@@ -347,7 +368,7 @@ getCommand singleLineMode = do
347handleCommand :: Command -> PSCI ()
368handleCommand :: Command -> PSCI ()
348handleCommand (Expression val) = handleDeclaration val
369handleCommand (Expression val) = handleDeclaration val
349handleCommand Help = PSCI $ outputStrLn helpMessage
370handleCommand Help = PSCI $ outputStrLn helpMessage
350−handleCommand (Import moduleName) = PSCI $ lift $ modify (updateImports moduleName)
371+handleCommand (Import moduleName) = handleImport moduleName
351handleCommand (Let l) = PSCI $ lift $ modify (updateLets l)
372handleCommand (Let l) = PSCI $ lift $ modify (updateLets l)
352handleCommand (LoadFile filePath) = do
373handleCommand (LoadFile filePath) = do
353 absPath <- psciIO $ expandTilde filePath
374 absPath <- psciIO $ expandTilde filePath
@@ -435,4 +456,3 @@ termInfo = Cmd.defTI
436main :: IO ()
457main :: IO ()
437main = Cmd.run (term, termInfo)
458main = Cmd.run (term, termInfo)