[Haskell-beginners] clarification on IO

Michael Easter codetojoy at gmail.com
Fri Feb 27 21:50:21 EST 2009


I've been reading RWH and this

I think I understand monads. I think I understand how IO is much different
from, e.g. Maybe, State, etc.

However there are some turns of phrase with respect to IO that have me
baffled.  I am giving a presentation
on monads next week, and hope you can help. (I'm not quite as lost as this
might imply!)

Q1: The web page mentions that normal Haskell functions cannot cause
side-effects, yet later talks about
side-effects with putStrLn. I assume the key point here that IO actions are,
by definition, _not_ normal functions?

Q2: Is it true to say that *any* monadic action *could *cause side-effects,
depending on the design of that
monad? i.e. Does one generalize from the IO monad to (possibly) an arbitrary
monad? *Musing* This must be true as
using State must surely be considered a side-effect.

Q3: The web page mentions IO as being a baton, or token, that is used to
thread/order the actions. Is true
that this is merely one simple perspective, with respect to order of
evaluation? This is hard to articulate,
but it seems to me that "in the IO monad" there is a large subsystem of
(inaccessible) state, machinery, etc.
Is it really a token?

Q4: Is the following idea accurate: a Haskell program is partitioned into 2
spaces. One is a sequence
of IO actions; the other is a space of pure functions and 'normal' Haskell
operations.  The execution of a
program begins with the main :: IO () action and, effectively, crosses from
one space to the other. In the
pure space, the math-like functions can be highly optimized but only insofar
as they do not disrupt the
implied order of the IO actions.  Because of the type system, the program
recognizes when it enters
"back" into the IO space and follows different, less optimized rules.

My concern is that the above is *not* accurate, but I don't know why.

thanks so much for your help
Michael Easter

Michael Easter
http://codetojoy.blogspot.com: Putting the thrill back in blog

http://youtube.com/ocitv -> Fun people doing serious software engineering
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090227/9c250695/attachment.htm

More information about the Beginners mailing list