
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". Cheers, Andres -- Andres Loeh, Universiteit Utrecht mailto:andres@cs.uu.nl mailto:mail@andres-loeh.de http://www.andres-loeh.de