module Control.ContStuff.Monads
(
Choice, listChoice, maybeChoice,
Cont, runCont, evalCont, modifyCont,
State, runState, evalState, execState,
OldWriter, runOldWriter, evalOldWriter, execOldWriter
)
where
import Control.Applicative
import Control.ContStuff.Trans
import Data.Functor.Identity
import Data.Monoid
type Choice r i a = ChoiceT r i Identity a
listChoice :: Choice [a] [a] a -> [a]
listChoice = runIdentity . listChoiceT
maybeChoice :: Choice (Maybe a) (Maybe a) a -> Maybe a
maybeChoice = runIdentity . maybeChoiceT
type Cont r a = ContT r Identity a
runCont :: (a -> r) -> Cont r a -> r
runCont k (ContT c) = runIdentity $ c (Identity . k)
evalCont :: Cont r r -> r
evalCont (ContT c) = runIdentity $ c pure
modifyCont :: (r -> r) -> Cont r ()
modifyCont = modifyContT
type OldWriter r w a = ContT (r, w) Identity a
runOldWriter :: Monoid w => OldWriter r w r -> (r, w)
runOldWriter = runIdentity . runOldWriterT
evalOldWriter :: Monoid w => OldWriter r w r -> r
evalOldWriter = fst . runIdentity . runOldWriterT
execOldWriter :: Monoid w => OldWriter r w r -> w
execOldWriter = snd . runIdentity . runOldWriterT
type State r s a = StateT r s Identity a
runState :: s -> (s -> a -> r) -> State r s a -> r
runState s0 k c = runIdentity $ runStateT s0 (\s1 -> Identity . k s1) c
evalState :: s -> State r s r -> r
evalState = (runIdentity .) . evalStateT
execState :: s -> State s s a -> s
execState = (runIdentity .) . execStateT