[Haskell-cafe] Re: Sometimes I wish there was a global variable

Simon Richard Clarkstone simon.clarkstone at gmail.com
Sun Mar 22 21:45:29 EDT 2009

Ok, replying to the list this time.  Darn Thunderbird not reading my 
mind again.

Rafael Cunha de Almeida wrote:
> Maurí­cio wrote:
>> In one module, you can write:
>> ----------
>> giveMeFunctions = do {
>>     newIORef ...
>>     newIORef ...
>>     newIORef ...
>>     (...)
>>     let f1 = ...
>>     let f2 = ...
>>     return (f1,f2)
>> ----------
>> and in the main:
>> (keyboardMouse,display) <- giveMeFunctions
> Doing it like that I could have all the definitions in one module, but
> it doesn't solve another important problem: keyboardMouse and display
> functions have to have as many parameters as there are IORefs.

I don't think so.  I think M means the two functions are closures 
capturing all the IORefs, i.e. they know which IORefs they refer to.  In 
OO terms, the two functions together are the two methods of an object 
that contains the IORefs as fields, and you needn't pass those IORefs 
in.  Note that calling giveMeFunctions twice will get you two distinct 
"objects", not the same one twice.


More information about the Haskell-Cafe mailing list