Simon Marlow wrote:
> > 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.
I think I remember the original thread that discussed this several
months ago. IIRC, there was some philosophical problems by assuming a
function could receive a World state as input and then return a
different one as output.(*)
When this philosophical impediment was pointed out, someone clarified
the point by saying that an "IO a" function type is *not* equivalent to
"World -> (World, a)". The result of an IO function is not an action, or
even a function that performs an action, but instructions on how to
perform an action. The result of a Haskell program (i.e., Main.main) is
a sequence of instructions for actions that need to be performed. It is
then up to the runtime system to execute these instructions.
An analogy was made to a Haskell program that produced FORTRAN source
code as output. The output is produced in a totally functional manner.
The runtime system is responsible for taking the output, compiling it,
and then executing the FORTRAN program.
That's the "theory" anyway. In practice, I imagine that there is a more
intimate conjunction between the runtime system and the Haskell code.
- Michael Hobbs
(*) One place where the World -> (World, a) model breaks down is when
the IO function is a blocking function such as "getChar :: IO Char". If
this function was equivalent to World -> (World, a) then that would mean
that the result is completely determined by the input World value. Also,
if the function was given the same World value on two separate occasions
then it would have to spit out the same result each time. Such a view
gets entangled with quantum physics, uncertainty principles, and other
philosophic theories about whether or not the universe is deterministic.