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 -> ...)?
I don't think so. Looking at the types:
Cont :: ((a -> r) -> r) -> Cont r a
callCC :: ((a -> Cont r b) -> Cont r a) -> Cont r a
If you only have callCC, there is no use of r as a type anywhere - it could be of any kind. So I don't know how you could translate something that uses it as a type, eg:
Cont (const 42) :: Cont Int a
I have no way of constraining r if I only have callCC.
Anyway, that's my hunch. Not terribly rigorous, but it seems convincing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With