[Haskell] threading mutable state through callbacks

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Tue Oct 12 13:59:11 EDT 2004

Jules Bean <jules at jellybean.co.uk> writes:

> I think what people are trying to suggest is an 'initialization
> phase' in the IO monad, which takes place "before" the pure
> functions are defined.

If it was done before, what could you use to specify initial value of
such a variable? Only literals? Constructors? Named constants? Results
of arithmetic operations? Results of arbitrary functions?

The well-definedness of a global IORef relies on the fact that
creation of an IORef doesn't have visible side effects, so it doesn't
matter when it happens, as long as it happens once between the
variable is used. An arbitrary IO computation doesn't have this

Unfortunately having only IORefs would be limiting. You couldn't
legally make stdin/stdout/stderr for example. Now they must rely
on compiler magic for something which doesn't seem to need magic
by nature (allocation of some MVars and other objects, not doing
actual I/O).

   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/

More information about the Haskell mailing list