[Haskell-beginners] Are monads pure?
andres at cs.uu.nl
Tue May 18 00:51:03 EDT 2010
> When I first started learning Haskell, I was under the impression that
> monads provided a way to encapsulate some imperative code so it didn't
> "contaminate" your functional code. But I think that's a misconception that
> I got because the first monad I dealt with was IO. Lately I've been reading
> more about monads, and (aside from IO), they are purely functional, aren't
> they? If they have state, they deal with it in a purely functional way.
> Behind the scenes, they thread the state through your computations so that
> you don't you don't have to bother with it. Is that correct? TIA.
You are right. IO is an exception, because it is a built-in type that
cannot be implemented in Haskell itself. Monads that are implemented in
Haskell without mentioning IO or interfacing via the FFI are generally
pure. Examples are state, errors, reader/writer, continuations,
lists, ... Nevertheless, people often refer to features such as state
and exceptions as "effects", and hence sometimes call code that makes
use of them "effectful" and code that does not "pure".
Andres Loeh, Universiteit Utrecht
mailto:andres at cs.uu.nl mailto:mail at andres-loeh.de
More information about the Beginners