You are absolutely right. The statement "The values of the IO monad are programs that do IO. " is somewhat nonsensical. Values don't do anything, they just are. But values of the IO monad *describe* how to do IO; they can be seen as a recipe for doing IO. A recipe doesn't cook a dish, but when the recipe is executed by a cook they creates a dish. An IO values doesn't do IO, but when it is executed by the runtime system IO happens.
This is one way of interpreting what the IO type means. (Another one is to say that Haskell is just an imperative programming language, but any imperative actions show up in the type.) -- Lennart 2009/2/4 Gregg Reynolds <d...@mobileink.com>: > On Wed, Feb 4, 2009 at 11:41 AM, Tim Newsham <news...@lava.net> wrote: >> >> I put up a small Monad explanation (I wouldn't quite call it >> a tutorial): >> http://www.thenewsh.com/~newsham/haskell/monad.html > > "The values of the IO monad are programs that do IO. " > > That's a fairly common representation, seems to work for lots of people, but > it caused me no end of trouble. Values are mathematical objects; how, I > asked myself, can they possibly /be/ programs that do IO (or actions, or > computations, or <your metaphor here>)? It doesn't make sense, says I, so I > must be misunderstanding something about "values"; better spend hours and > hours researching and trying to figure this out. But it turns out the > answer is simple: they can't. They're not actions, or IO procedures, or > anything else other than plain old mathematical values, no different than > '2' or Int -> Char. They happen to correspond in some way to the external > physical behavior of the program, but that correspondence is an > implementation detail beyond the scope of the formal (mathematical) > semantics of the language. You don't even need monads for this part; they > only enter the picture in order to provide ordered evaluation. In fact > there really aren't any "monadic values", since a monad is pure morphism; > the values at issue are "functoric values" if anything. It's (the > implementation of) getChar the does the IO, not IO Char. > > So you could say that the monad itself is a purely mathematical structure > that has the felicitous if accidental side effect of imposing temporal > sequence on the physical interpretation (events) associated with the > program. > > -g > > > _______________________________________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/mailman/listinfo/haskell-cafe > > _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe