Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE FlexibleContexts #-}
  2. module Execute
  3.        ( updateMap
  4.        , executeEcho
  5.        , executeCd
  6.        , executePwd
  7.        , executeExit
  8.        ) where
  9.  
  10. import Control.Monad.Reader (MonadIO, liftIO)
  11. import Data.Map (Map, empty, insert)
  12. import Control.Monad.State (MonadState, get, modify)
  13. import Control.Monad.Except (MonadError)
  14. import Action
  15. import Exception
  16. import System.Posix.Directory (getWorkingDirectory, changeWorkingDirectory)
  17. import System.Exit (exitWith, ExitCode(ExitSuccess))
  18.  
  19. updateMap :: ( MonadState (Map String String)  m
  20.              , MonadError Exception m
  21.              ) => [Action] -> m ()
  22. updateMap [] = return ()                
  23. updateMap ((Assigment key value) : t) = do
  24.                                         modify $ insert key value
  25.                                         updateMap t
  26.  
  27.  
  28.  
  29. executeEcho :: MonadIO m => String -> m ()
  30. executeEcho s = liftIO $ print s  
  31.  
  32. executeCd :: MonadIO m => String -> m ()
  33. executeCd s = liftIO $ changeWorkingDirectory s  
  34.  
  35. executePwd :: MonadIO m => m ()
  36. executePwd = liftIO $ do
  37.                       path <- getWorkingDirectory
  38.                       print path
  39.  
  40. executeExit :: MonadIO m => m ()
  41. executeExit = liftIO $ exitWith ExitSuccess
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement