IO-System

Seth Kurtzberg seth@cql.com
Mon, 16 Sep 2002 18:03:05 -0700


As Simon explained to me recently, that is the problem with this type of lazy 
IO:  the sequence of operations is undefined.  There is no requirement that 
the read consume only the characters that have already been requested; in 
fact, that would likely be horribly inefficient.  Plus, it is quite possible 
that the underlying operating system is consuming both characters before it 
feeds the first one to GHC.

So, this type of IO should only be used when you don't care about the precise 
order of operations.

On Monday 16 September 2002 18:06, David Sabel wrote:
> > The runtime system mostly has no concept of IO vs. non-IO evaluation.
> > The IO monad is implemented as the following type:
> >
> >   newtype IO a = IO (State# RealWorld ->
> >    (# State# RealWorld, a #)
> >
> > which means that an IO action is simply a function from the world state
> > to a pair of a new world state and a value.  In other words, it's a
> > straightfoward state monad, except that we use some optimised
> > representations to eliminate some of the overhead of passing the state
> > around.
> >
> > Cheers,
> > Simon
>
> Ok so far, but when is the IO action performed?
>
> Look at this small programm:
>
>     module Main(main) where
>
>     main = echoTwice
>
>     echo = getChar >>= putChar
>
>     echoTwice = echo >> echo
>
> while executing: the program reads first two chararcters and then it writes
> the characters, but
> in my opinion it would be right to read one character, then write one
> characater, then read, then write.
> What's the reason for it?
>
> ----------------------------------
> David Sabel
> JWGU Frankfurt
>
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users@haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

-- 
-----------------------------------
Seth Kurtzberg
M. I. S. Corp.
1-480-661-1849