[Haskell-cafe] Can we come out of a monad?

Alexey Khudyakov alexey.skladnoy at gmail.com
Fri Jul 30 17:49:43 EDT 2010

On Fri, 30 Jul 2010 09:29:59 +0200
Stefan Holdermans <stefan at vectorfabrics.com> wrote:

> Jason,
> > There is one case where you can break out of a monad without knowing which
> > monad it is.  Well, kind of.  It's cheating in a way because it does force
> > the use of the Identity monad.  Even if it's cheating, it's still very
> > clever and interesting.
> How is this cheating?  Or better, how is this breaking out of a monad "without
> knowing which monad it is"?  It isn't. You know exactly which monad you're
> breaking out: it's the identity monad.  That's what happens if you put
> quantifiers in negative positions: here, you are not escaping out of an
> arbitrary monad (which you can't), but escaping out of a very specific monad.
No I think here we breaking out from _arbitrary_ monad. If monadic
function works for every monad then it must work for identity monad
too. Here is simplest form of purify function:

> purify2 :: (forall m . Monad m => m a) -> a
> purify2 m = runIdentity m

This proves interesting fact. Value could be removed from monad if no
constrain is put on the type of monad. Moreover it Monad in this
example could be replaced with Functor or other type class

I wonder could this function be written without resorting to concrete

Alexey Khudyakov <alexey.skladnoy at gmail.com>

More information about the Haskell-Cafe mailing list