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.Monoid
type Choice r i a = ChoiceT r i Id a
listChoice :: Choice [a] [a] a -> [a]
listChoice = getId . listChoiceT
maybeChoice :: Choice (Maybe a) (Maybe a) a -> Maybe a
maybeChoice = getId . maybeChoiceT
type Cont r a = ContT r Id a
runCont :: (a -> r) -> Cont r a -> r
runCont k (ContT c) = getId $ c (Id . k)
evalCont :: Cont r r -> r
evalCont (ContT c) = getId $ c pure
modifyCont :: (r -> r) -> Cont r ()
modifyCont = modifyContT
type OldWriter r w a = ContT (r, w) Id a
runOldWriter :: Monoid w => OldWriter r w r -> (r, w)
runOldWriter = getId . runOldWriterT
evalOldWriter :: Monoid w => OldWriter r w r -> r
evalOldWriter = fst . getId . runOldWriterT
execOldWriter :: Monoid w => OldWriter r w r -> w
execOldWriter = snd . getId . runOldWriterT
type State r s a = StateT r s Id a
runState :: s -> (s -> a -> r) -> State r s a -> r
runState s0 k c = getId $ runStateT s0 (\s1 -> Id . k s1) c
evalState :: s -> State r s r -> r
evalState = (getId .) . evalStateT
execState :: s -> State s s a -> s
execState = (getId .) . execStateT