2 Aug 22:03 2005

## Practical introduction to monads

I've started learning Haskell, and I'm going through all the tutorial material I can find - there's a lot of good stuff available. One thing I haven't found a really good discussion of, is practical examples of building monads. There's plenty of discussion of the IO monad, and the state monad, and a lot of good theory on monads, but although I've seen tantalising statements about how powerful the ability to define your own monads can be, but no really concrete examples - something along the lines of - here is problem X - this might be our first cut at coding it - we can abstract out this stuff, as a monad - see how the code looks now, how much cleaner it is (I've seen this type of model developing a state monad, but I'm looking for a more application-specific approach). Also, a lot of (non-IO) monad code I've seen seems to revolve around higher order features like monad combinators, which, while certainly powerful, still make my head explode. On the other hand, monadic IO feels entirely comprehensible, revolving round do-notation, and looking reassuringly sequential and imperative Surely there are other uses of monads which can feel familiar to non-functional programmers? Otherwise, I'm still left with the (inaccurate, and unhelpful) impression that "IO is a badly integrated exception"... I don't know if the above makes sense. I've struggled with this for a while now, and haven't managed to express my confusion any more clearly - for which I apologise. I'd appreciate any pointers or(Continue reading)