From: gabriele renzi Date: 2005-10-01T02:41:45+09:00 Subject: Re: In your opinion.... Karl von Laudermann ha scritto: > I certainly don't understand the monad. I read some introductory > material re: Haskell just a couple of weeks ago, out of curiosity about > the language. My understanding of the monad concept and Haskell's use > thereof is basically this: > > - Haskell is a purely functional language > - Purely functional languages cannot have side effects > - A language that can't do I/O is useless, so we need a way to put side > effects into a purely functional language > Therefore: > - We'll put I/O subroutines into Haskell, *but* we'll call them > "monads", and that magically fixes the problem somehow > > I'm sure that my understanding is wrong, but that's what I came away > with. # warning: this is just my understanding of monads as an haskell noob # and it may be completely wrong :) First, IIRC Haskell had IO even before the "monadic revolution", it was just even harder to understand ;) What I had understand about monads is not that they allow you to express a single point where side effect will happen, and to order them. Thus any side effect is not really hidden, it is just structured in a way that it play nicely with the pure functional part of the code. Think for example of the IO monad: it allows you to state that you should, say, print "hello" before "world". The rest of the program is still happy, functional and lazy, since he does'nt really care about the console output. OTOH, when you want to read a string, you can't handle it in the pure functional side of the code, since it won't be referentially transparent. Thus you happily write your functional processing stuff, then incidentally you ask a monad to use that functional stuff on something that will come from the user. I think of it as somewhat similar to continuation passing style. You don't ever "return" from a function in CPS, you just say to the next continuation "hey, here's my value, do stuff with it". With monads it is the same, you just say to the monad "hey do this stuff, and take care of the rest of the program". At least, I think :)