[Haskell-cafe] Practical introduction to monads
Paul Moore
pf_moore at yahoo.co.uk
Tue Aug 2 16:03:49 EDT 2005
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
explanations.
FWIW, I've read (among other papers) "Why Functional Programming
Matters", "A Gentle Introduction to Haskell", Hal Daume's "Yet Another
Haskell Tutorial", Simon Peyton Jones' "Tackling the Awkward Squad",
and "Haskell: The Craft of Functional Programming". I don't claim to
have digested all of this - indeed, there are probably many areas
I've only skimmed - so pointers to areas in these documents I might
have missed would be appreciated. On the other hand, pointers to
papers I've missed altogether would also be gratefully received.
Thanks in advance for any help,
Paul.
--
There is a theory which states that if ever anybody discovers exactly
what the Universe is for and why it is here, it will instantly
disappear and be replaced by something even more bizarre and
inexplicable. There is another theory which states that this has
already happened. -- Douglas Adams
More information about the Haskell-Cafe
mailing list