Created
June 23, 2009 19:34
-
-
Save deontologician/134778 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# OPTIONS_GHC -fglasgow-exts #-} | |
module System.Console.CommandLine where | |
import System.Console.Haskeline | |
import Control.Monad.Trans (lift, MonadTrans) | |
import Control.Monad.State | |
import Control.Applicative | |
import qualified Data.Map as Map | |
type Callback m a = [String] -> CommandLineT m a | |
type CallbackList m a = Map.Map String (Callback m a) | |
type Environment = Map.Map String String | |
data CommandState m a = CS { registry :: Environment | |
, callbacks :: CallbackList m a | |
} | |
newtype CommandLineT m a = CommandLineT (StateT (CommandState m a) (InputT m) a) | |
deriving(Monad) | |
runCommandLine :: (MonadException m) => CommandLineT m a -> CommandState m a -> m a | |
runCommandLine (CommandLineT x) cState = | |
runInputT defaultSettings (evalStateT x cState) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment