Ashley Yakeley | 25 Aug 04:34

Re: [Haskell] Top Level <-

Duncan Coutts wrote:
> This topic came up in #haskell this evening...
> 
> On Sun, 2008-08-24 at 16:12 -0700, Ashley Yakeley wrote:
>> 1. Global mutable state. For instance, here's the count variable for 
>> Data.Unique rewritten:
>>
>>    uniqSource :: MVar Integer
>>    uniqSource <- newMVarTL 0
>>
>> Isn't that much nicer?
>> <http://haskell.org/haskellwiki/Top_level_mutable_state>
> 
> It's nicer syntax but it's still not true. There's still no such thing
> as a global variable. There's always a scope.
> 
> In this case what scope are we looking for? Process scope? Only one
> instance of ïğżuniqSource per process?

It is actually process scope, I believe. But it's one instance of 
"base-3.0.2.0:Data.Unique.uniqSource" per process: we don't care if 
there's also a "base-4.0:Data.Unique.uniqSource". The reason we don't 
care in this case is that base-3.0.2.0:Data.Unique.Unique and 
base-4.0:Data.Unique.Unique are different types, so they can't collide. 
These are different names in the same scope.

The scope I'm interested in is "Main.main" scope, i.e., the initialiser 
should be run no more than once per run of "main".

--

-- 
Ashley Yakeley

Gmane