[Haskell-cafe] Current situation regarding global IORefs

Brian Hulley brianh at metamilk.com
Sat Apr 29 10:58:12 EDT 2006

Lennart Augustsson wrote:
> And yes, somewhere there's some global mutable state in the OS.
> I've never claimed that it should be totally forbidden.  Various
> circumstances forces it upon us.  What I've been claiming is that
> it should be avoided where possible.  Which is almost always.

Thus there seems to be agreement that whereas this should be avoided where 
possible, it is still needed in some cases.

Therefore the question arises as to how to safely incorporate this into the 
language. As everyone knows, use of unsafePerformIO could break the type 
system without a programmer knowing it, but I think I am right in saying 
that if only monomorphic refs were allowed at the top level, type safety 
would be ensured (so there would be no need for the truly horrible value 
restriction that infects the whole of SML for example)

Therefore I propose a new keyword to define monomorphic top level IORefs, 
something like:

augment ref = monomorphicvalue -- just a plain value not a monadic 

where "augment" refers to the augmentation of the RealWorld state by the 
state of ref as in John's suggestion to use "augmented IO" in preference to 
"global mutable state"

The use of a plain value to initialize the ref rather than a monadic 
computation would ensure that there would be no problems with trying to work 
out which order to initialize top level refs that are dependent on values of 
refs in other modules since there could be no dependencies.

Regards, Brian. 

More information about the Haskell-Cafe mailing list