@@ -28,7 +28,7 @@ import qualified Data.Map as M
2828import Control.Applicative
2929import Control.Monad
3030import Control.Monad.Error (ErrorT (.. ), MonadError )
31- import Control.Monad.Error.Class ( MonadError ( .. ) )
31+ import Control.Monad.Reader ( MonadReader , ReaderT , runReaderT )
3232import Control.Monad.Trans.Class
3333import Control.Monad.Trans.Maybe (MaybeT (.. ), runMaybeT )
3434import Control.Monad.Trans.State.Strict
@@ -150,7 +150,7 @@ loadAllImportedModules = do
150150 modulesOrFirstError <- psciIO $ loadAllModules files
151151 case modulesOrFirstError of
152152 Left err -> psciIO $ print err
153- Right modules -> PSCI . lift . modify $ \ st -> st { psciLoadedModules = modules }
153+ Right modules -> PSCI . lift . modify $ \ st -> st { psciLoadedModules = modules }
154154
155155-- |
156156-- Expands tilde in path.
@@ -314,35 +314,33 @@ completion = completeWordWithPrev Nothing " \t\n\r" findCompletions
314314-- | Compilation options.
315315--
316316options :: P. Options P. Make
317- options = P. Options False False False Nothing False False P. MakeOptions
317+ options = P. Options False False False Nothing False False False P. MakeOptions
318318
319319-- |
320320-- PSCI monad
321321--
322322newtype PSCI a = PSCI { runPSCI :: InputT (StateT PSCiState IO ) a } deriving (Functor , Applicative , Monad )
323323
324324psciIO :: IO a -> PSCI a
325- psciIO io = PSCI ( lift ( lift io))
325+ psciIO io = PSCI . lift $ lift io
326326
327- newtype Make a = Make { unMake :: ErrorT String IO a } deriving (Functor , Applicative , Monad , MonadError String )
327+ newtype Make a = Make { unMake :: ReaderT (P. Options P. Make ) (ErrorT String IO ) a }
328+ deriving (Functor , Applicative , Monad , MonadError String , MonadReader (P.Options P.Make ))
328329
329330runMake :: Make a -> IO (Either String a )
330- runMake = runErrorT . unMake
331+ runMake = runErrorT . flip runReaderT options . unMake
331332
332333makeIO :: IO a -> Make a
333- makeIO = Make . ErrorT . fmap (either (Left . show ) Right ) . tryIOError
334+ makeIO = Make . lift . ErrorT . fmap (either (Left . show ) Right ) . tryIOError
334335
335336instance P. MonadMake Make where
336337 getTimestamp path = makeIO $ do
337338 exists <- doesFileExist path
338- if exists
339- then Just <$> getModificationTime path
340- else return Nothing
339+ traverse (const $ getModificationTime path) $ guard exists
341340 readTextFile path = makeIO $ readFile path
342341 writeTextFile path text = makeIO $ do
343342 mkdirp path
344343 writeFile path text
345- liftError = either throwError return
346344 progress s = unless (s == " Compiling $PSCI" ) $ makeIO . putStrLn $ s
347345
348346mkdirp :: FilePath -> IO ()
@@ -402,7 +400,7 @@ handleDeclaration :: P.Expr -> PSCI ()
402400handleDeclaration val = do
403401 st <- PSCI $ lift get
404402 let m = createTemporaryModule True st val
405- e <- psciIO . runMake $ P. make modulesDir options (psciLoadedModules st ++ [(Left P. RebuildAlways , m)]) []
403+ e <- psciIO . runMake $ P. make modulesDir (psciLoadedModules st ++ [(Left P. RebuildAlways , m)]) []
406404 case e of
407405 Left err -> PSCI $ outputStrLn err
408406 Right _ -> do
@@ -423,7 +421,7 @@ handleLet ds = do
423421 st <- PSCI $ lift get
424422 let st' = updateLets ds st
425423 let m = createTemporaryModule False st' (P. ObjectLiteral [] )
426- e <- psciIO . runMake $ P. make modulesDir options (psciLoadedModules st' ++ [(Left P. RebuildAlways , m)]) []
424+ e <- psciIO . runMake $ P. make modulesDir (psciLoadedModules st' ++ [(Left P. RebuildAlways , m)]) []
427425 case e of
428426 Left err -> PSCI $ outputStrLn err
429427 Right _ -> PSCI $ lift (put st')
@@ -456,7 +454,7 @@ handleImport :: P.ModuleName -> PSCI ()
456454handleImport moduleName = do
457455 st <- updateImports moduleName <$> PSCI (lift get)
458456 let m = createTemporaryModuleForImports st
459- e <- psciIO . runMake $ P. make modulesDir options (psciLoadedModules st ++ [(Left P. RebuildAlways , m)]) []
457+ e <- psciIO . runMake $ P. make modulesDir (psciLoadedModules st ++ [(Left P. RebuildAlways , m)]) []
460458 case e of
461459 Left err -> PSCI $ outputStrLn err
462460 Right _ -> do
@@ -470,7 +468,7 @@ handleTypeOf :: P.Expr -> PSCI ()
470468handleTypeOf val = do
471469 st <- PSCI $ lift get
472470 let m = createTemporaryModule False st val
473- e <- psciIO . runMake $ P. make modulesDir options (psciLoadedModules st ++ [(Left P. RebuildAlways , m)]) []
471+ e <- psciIO . runMake $ P. make modulesDir (psciLoadedModules st ++ [(Left P. RebuildAlways , m)]) []
474472 case e of
475473 Left err -> PSCI $ outputStrLn err
476474 Right env' ->
@@ -504,7 +502,7 @@ handleBrowse :: P.ModuleName -> PSCI ()
504502handleBrowse moduleName = do
505503 st <- PSCI $ lift get
506504 let loadedModules = psciLoadedModules st
507- env <- psciIO . runMake $ P. make modulesDir options loadedModules []
505+ env <- psciIO . runMake $ P. make modulesDir loadedModules []
508506 case env of
509507 Left err -> PSCI $ outputStrLn err
510508 Right env' ->
@@ -520,7 +518,7 @@ handleKindOf typ = do
520518 st <- PSCI $ lift get
521519 let m = createTemporaryModuleForKind st typ
522520 mName = P. ModuleName [P. ProperName " $PSCI" ]
523- e <- psciIO . runMake $ P. make modulesDir options (psciLoadedModules st ++ [(Left P. RebuildAlways , m)]) []
521+ e <- psciIO . runMake $ P. make modulesDir (psciLoadedModules st ++ [(Left P. RebuildAlways , m)]) []
524522 case e of
525523 Left err -> PSCI $ outputStrLn err
526524 Right env' ->
@@ -571,7 +569,7 @@ handleCommand (LoadFile filePath) = do
571569 PSCI . outputStrLn $ " Couldn't locate: " ++ filePath
572570handleCommand Reset = do
573571 files <- psciImportedFilenames <$> PSCI (lift get)
574- PSCI . lift . modify $ \ st -> st
572+ PSCI . lift . modify $ \ st -> st
575573 { psciImportedFilenames = files
576574 , psciImportedModuleNames = defaultImports
577575 , psciLetBindings = []
0 commit comments