From: Paolo Capriotti
Date: 2005-10-01T01:50:31+09:00
Subject: Re: In your opinion....
On 9/30/05, Karl von Laudermann wrote:
>
> 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.
That's not quite right, imho. An IO monad encapsulates a sort of "IO
operation", and IO routines are not monads themselves. Instead, they
_return_ IO monads.
In spite of monads, I think that Haskell code can still be considered
without side effects. Something like
main = do c <- getChar
putChar c
should be thought as a manipulation of abstract "IO operations". It
produces side effects only because the resulting monad is finally
evaluated (i.e. executed), and that cannot be done inside the Haskell
domain.
Anyway, monads are not just for IO. There are plenty of monadic
classes in the ghc library which have nothing to do with IO. A list is
a monad, for example, as well as a parser.
I'm still considering the monad subject from the point of view of Ruby
programming. It may seem that monads belong to the pure functional
world only, and Ruby does not need them, but...
when we write ary.map{|i| i+1}, aren't we using the fact that Array is
a functor (in the mathematical sense)? To some extent, inject can be
considered as a way to exploit the monadic properties of the Array
functor.
However, can the monad concept be defined in Ruby in some generality?
Paolo Capriotti