Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE FlexibleContexts #-}
- module Execute
- ( updateMap
- , executeEcho
- , executeCd
- , executePwd
- , executeExit
- ) where
- import Control.Monad.Reader (MonadIO, liftIO)
- import Data.Map (Map, empty, insert)
- import Control.Monad.State (MonadState, get, modify)
- import Control.Monad.Except (MonadError)
- import Action
- import Exception
- import System.Posix.Directory (getWorkingDirectory, changeWorkingDirectory)
- import System.Exit (exitWith, ExitCode(ExitSuccess))
- updateMap :: ( MonadState (Map String String) m
- , MonadError Exception m
- ) => [Action] -> m ()
- updateMap [] = return ()
- updateMap ((Assigment key value) : t) = do
- modify $ insert key value
- updateMap t
- executeEcho :: MonadIO m => String -> m ()
- executeEcho s = liftIO $ print s
- executeCd :: MonadIO m => String -> m ()
- executeCd s = liftIO $ changeWorkingDirectory s
- executePwd :: MonadIO m => m ()
- executePwd = liftIO $ do
- path <- getWorkingDirectory
- print path
- executeExit :: MonadIO m => m ()
- executeExit = liftIO $ exitWith ExitSuccess
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement