@@ -233,6 +233,14 @@ instance P.MonadMake Make where
233233mkdirp :: FilePath -> IO ()
234234mkdirp = createDirectoryIfMissing True . takeDirectory
235235
236+-- |
237+-- Just an empty module.
238+--
239+emptyModule :: P.Module
240+emptyModule =
241+ let moduleName = P.ModuleName [P.ProperName "$PSCI"]
242+ in P.Module moduleName [] Nothing
243+
236244-- |
237245-- Makes a volatile module to execute the current expression.
238246--
@@ -288,6 +296,19 @@ handleDeclaration value = do
288296 Just (ExitFailure _, _, err) -> PSCI $ outputStrLn err
289297 Nothing -> PSCI $ outputStrLn "Couldn't find node.js"
290298
299+-- |
300+-- Imports a module, preserving the initial state on failure.
301+--
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)]) []
306+ case e of
307+ Left err -> PSCI $ outputStrLn err
308+ Right _ -> do
309+ PSCI $ lift $ put s
310+ return ()
311+
291312-- |
292313-- Takes a value and prints its type
293314--
@@ -347,7 +368,7 @@ getCommand singleLineMode = do
347368handleCommand :: Command -> PSCI ()
348369handleCommand (Expression val) = handleDeclaration val
349370handleCommand Help = PSCI $ outputStrLn helpMessage
350−handleCommand (Import moduleName) = PSCI $ lift $ modify (updateImports moduleName)
371+handleCommand (Import moduleName) = handleImport moduleName
351372handleCommand (Let l) = PSCI $ lift $ modify (updateLets l)
352373handleCommand (LoadFile filePath) = do
353374 absPath <- psciIO $ expandTilde filePath
@@ -435,4 +456,3 @@ termInfo = Cmd.defTI
435456
436457main :: IO ()
437458main = Cmd.run (term, termInfo)
438−