Copyright | (c) Samuel Schlesinger 2020 |
---|---|
License | MIT |
Maintainer | sgschlesinger@gmail.com |
Stability | experimental |
Portability | POSIX, Windows |
Safe Haskell | Safe |
Language | Haskell2010 |
Synopsis
- data CommanderT state m a
- = Action (state -> m (CommanderT state m a, state))
- | Defeat
- | Victory a
- runCommanderT :: Monad m => CommanderT state m a -> state -> m (Maybe a)
The CommanderT Monad
The CommanderT
monad is how your CLI programs are interpreted by run
.
It has the ability to backtrack and it maintains some state.
data CommanderT state m a Source #
A CommanderT
action is a metaphor for a military commander. At each
step, we have a new Action
to take, or we could have experienced
Defeat
, or we can see Victory
. While a real life commander
worries about moving his troops around in order to achieve a victory in
battle, a CommanderT
worries about iteratively transforming a state
to find some value. We will deal with the subset of these actions where
every function must decrease the size of the state, as those are the
actions for which this is a monad.
Action (state -> m (CommanderT state m a, state)) | |
Defeat | |
Victory a |
Instances
MonadTrans (CommanderT state) Source # | |
Defined in Control.Monad.Commander lift :: Monad m => m a -> CommanderT state m a # | |
Monad m => Monad (CommanderT state m) Source # | |
Defined in Control.Monad.Commander (>>=) :: CommanderT state m a -> (a -> CommanderT state m b) -> CommanderT state m b # (>>) :: CommanderT state m a -> CommanderT state m b -> CommanderT state m b # return :: a -> CommanderT state m a # fail :: String -> CommanderT state m a # | |
Functor m => Functor (CommanderT state m) Source # | |
Defined in Control.Monad.Commander fmap :: (a -> b) -> CommanderT state m a -> CommanderT state m b # (<$) :: a -> CommanderT state m b -> CommanderT state m a # | |
Monad m => Applicative (CommanderT state m) Source # | |
Defined in Control.Monad.Commander pure :: a -> CommanderT state m a # (<*>) :: CommanderT state m (a -> b) -> CommanderT state m a -> CommanderT state m b # liftA2 :: (a -> b -> c) -> CommanderT state m a -> CommanderT state m b -> CommanderT state m c # (*>) :: CommanderT state m a -> CommanderT state m b -> CommanderT state m b # (<*) :: CommanderT state m a -> CommanderT state m b -> CommanderT state m a # | |
MonadIO m => MonadIO (CommanderT state m) Source # | |
Defined in Control.Monad.Commander liftIO :: IO a -> CommanderT state m a # | |
Monad m => Alternative (CommanderT state m) Source # | |
Defined in Control.Monad.Commander empty :: CommanderT state m a # (<|>) :: CommanderT state m a -> CommanderT state m a -> CommanderT state m a # some :: CommanderT state m a -> CommanderT state m [a] # many :: CommanderT state m a -> CommanderT state m [a] # |
runCommanderT :: Monad m => CommanderT state m a -> state -> m (Maybe a) Source #
We can run a CommanderT
action on a state and see if it has
a successful campaign.