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

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Fri Jul 30 06:19:16 EDT 2010

Kevin Jardine <kevinjardine at gmail.com> writes:

> I think that we are having a terminology confusion here. For me, a
> pure function is one that does not operate inside a monad. Eg. ++,
> map, etc.

No, a pure function is one without any side effects.

> It was at one point my belief that although code in monads could call
> pure functions, code in pure functions could not call functions that
> operated inside a monad.

Not at all.  I can do something like "map (liftM succ) [Just 2,
Nothing]", where liftM is a monadic function.  The thing is that I'm
applying it to a "pure" monad (i.e. the Maybe monad doesn't have side

> I was then introduced to functions such as execState and
> unsafePerformIO which appear to prove that my original belief was
> false.

unsafePerformIO is the wild-card here; it's whole purpose is to be able
to say that "this IO action (usually linking to a C library or some
such) is pure, promise!!!".

> Currently I am in a state of deep confusion, but that is OK, because
> it means that I am learning something new!

The big point here that you seem to be tied up in is that Monad /=

I see three broad classifications of Monads:

1) Data structures that can be used as monads, such as [a] and Maybe a.

2) Special monadic wrappers/transformers such as State, Reader,
   etc. which allow you to act as if something is being done
   sequentially (which is the whole point of >>=) but is actually a pure
   function.  The ST monad also appears to be able to be used like this
   if you use runST.

3) Side-effect monads: IO, STM, ST (used with stToIO), etc.  The
   "classical" monads, so to speak which you seem to be thinking about.

Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com

More information about the Haskell-Cafe mailing list