Skip to content

Instantly share code, notes, and snippets.

@deontologician
Created June 23, 2009 19:34
Show Gist options
  • Save deontologician/134778 to your computer and use it in GitHub Desktop.
Save deontologician/134778 to your computer and use it in GitHub Desktop.
{-# 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