> Probably so, I do have difficulty understanding this. The point I was
> trying to make is that as far as Haskell is concerned, that
> there is no
> difference between values of type (IO a) and any other
> values. The fact
> that once evaluated these values cause IO operations to be
> performed (by
> some entity outside the Haskell program) is irrelevant. This
> is, of course,
> merely what I understand as the Haskell view from other
> correspondants on
> this list, not an indisputable truth.
Strictly speaking, you can't "evaluate" a value of type (IO a) and have it
perform some I/O operations. In fact, there's no way to perform an IO
computation in Haskell other than binding it to a value called 'Main.main',
compiling and running it. (*)
So, IO behaves somewhat like a function. If you write
main = seq (putStr "hello world!") (return ())
what happens? Nothing. I don't think this intended behaviour is stated
explicitly in the report, incidentally.
(*) well, GHC has unsafePerformIO, but that's another story.
> > That abstract type can be viewed as a state monad whose state is the
> > World, i.e.
> > IO a = (World -> (a, World))
> > and so you can also describe functions going from one state
> of the world
> > to another (producing a value as result), but only in abstract ways.
>
> I was recently assured (by a message on this list) that as
> far as Haskell
> is concerned a value of type (IO a) is simply an abstract
> data type, not
> a world transforming function. But if you do interpret it as
> such, what
> you've got is world as value IO, like Clean.
All known Haskell compilers implement the IO type as a function type,
something like (World -> (World, a)). You can think of the monad as just a
convenient way to hide the passing around of the world token.
And because it is abstract, compilers are free to implement it however they
like. GHC implements the World token by a void type, for example - it's
kept around as a placeholder to ensure the correct ordering of operations,
but expands into almost no code.
Cheers,
Simon