]>
Paolo,
> I'm disappointed with myself and my incredibly low IQ. Late this
> evening I decided -- and this is the third time -- to be enlightened
> by the concept of monad.
>
> I like functional programming, but monads [1] must be too little to be
> grabbed by my mind. This time the interest in monads was aroused by
> the interesting article of David Teller, Arnaud Spiwack and Till
> Varoquaux [2] about the error monad, but for using the library they
> wrote I need at least some knowledge about monads and the do-notation.
Concerning the I/O monad, maybe a useful approach to think about
a member of a monadic type is to regard it as a "plan to do something".
A plan is - essentially - a data structure, i.e. a mathematical value.
There are well defined operations on plans, but there are only very
few of them. Basically, when you have a plan A do do something and a
plan B to do something, you can use those to make a plan to first do A
and then do B. Also, if you have a plan A to produce X, and, for some X,
you can find a plan B that utilizes X, you can assemble a combined plan
that says: "Use plan A to get X and then do that plan B which
corresponds to this X". After all, as plans have a chronological aspect
to them, essentially all you eventually really can do in terms of
operations on plans is to do one after the other.
So, speaking e.g. about Haskell's monadic I/O, you don't really have a
concept of "printing something", but you do have a concept of
"operations on plans that contain printing instructions". Now, in
a lazy language, such a plan can be constructed lazily, conceptually
infinietly wide and deep, and hence capture all computations. And then,
there is a special "magic wand", which says: "If you give me a plan,
I'll execute it for you". That's it.
> I tried with some tutorials found around, but I still cannot catch the
> point: what the hell is a monad?
>
> I ask you all: can anyone make me a practical example, something
> involving strings, files, the network, an image or sound processing
> algorithm, something vaguely real? Not abstract mathematical
> structures, beautiful algebraic properties and general statements,
> please: the net is full of such tutorials, especially Haskell fan
> sites ;-)
Computer scientists like to obfuscate dead simple ideas with complicated
looking mathematics to deter commonsense-oriented people from making
embarassing observations, such as that computer science was
unable to see something that actually is pretty much obvious -
for ages... ;-)
--
best regards,
Thomas Fischbacher
t.fischbacher@soton.ac.uk