James G. Sack (jim) wrote:
I know very little about functional programming, but I keep getting
stuck on claims that assume the absence of side effects. Is code that
has side effects (eg, any i/o) not allowed IN a function by some kind of
formality? Is side-effects stuff forced into some special code artifact
that is outside the meaning of _function_ -- or what?
It's not really a code *artifact* as such. One way of understanding
Haskell is that it computes a series of I/O operations, which it then
returns as the value of "main", which then does the computer I/O. :-)
Obviously, it's not exactly that, but it's one way of wrapping your head
around it.
All the side effects are invisible to the functional program. When you
call "read a character" three times in a row, you're actually calling it
with three different arguments (which are what the "monad" is). In
addition, part of the result of the first call is passed as an argument
to the second call, and part of the result of the second call is passed
as an argument to the third call, so normal functional execution rules
make sure the I/O progresses in order, just like normal functional rules
ensures that in f(g(x)) that g is evaluated before f is.
--
Darren New / San Diego, CA, USA (PST)
I bet exercise equipment would be a lot more
expensive if we had evolved from starfish.
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg