[Haskell-cafe] Re: Can we come out of a monad?
es at ertes.de
Fri Jul 30 11:38:57 EDT 2010
it's a bit hidden in Haskell, but a monad instance consists of three
fmap :: (a -> b) -> (m a -> m b)
return :: a -> m a
join :: m (m a) -> m a
Nothing more is needed to define a monad. In Haskell, a monad is
expressed by 'return' and (>>=) instead, but this is equivalent.
The types of these functions tell you what you can do with the monad.
You can put values into it and you can turn a doubly wrapped monadic
value into a singly wrapped monadic value (usually by dropping
Unless there is a function, which has deeper comprehension of a monadic
value than these two functions, like 'runState' or 'head', you can never
get values out of it. For the IO monad no such function can exist.
This is intentional.
C K Kashyap <ckkashyap at gmail.com> wrote:
> In the code here -
> If I look at the type of modifiedImage, its simply ByteString - but isn't it
> actually getting into and back out of the state monad? I am of the
> understanding that once you into a monad, you cant get out of it? Is this
> breaking the "monad" scheme?
nightmare = unsafePerformIO (getWrongWife >>= sex)
More information about the Haskell-Cafe