The state monad "interface"
class MonadState s m where
get :: m s
put :: s -> m ()
(+ return and bind) allows to construct any possible computation with State monad without using State
constructor. For example, State $ \s -> (s+1, s-1)
can be written as
do s <- get
put (s-1)
return (s+1)
Similarily, I never have to use Reader
constructor, because I can create that computation using ask
, return
and (>>=)
. Precisely: Reader f == ask >>= return . f
.
Is it the same true for continuations - is it possible to write all instances of Cont r a
using callCC
(the only function in MonadCont
), return and bind, and never type something like Cont (\c -> ...)
?