[Haskell-cafe] Re: [Haskell] Top Level <-
ganesh at earth.li
Sat Aug 30 07:14:37 EDT 2008
On Sat, 30 Aug 2008, Ashley Yakeley wrote:
> Ganesh Sittampalam wrote:
>> If you want to standardise a language feature, you have to explain its
>> behaviour properly. This is one part of the necessary explanation.
>> To be concrete about scenarios I was considering, what happens if:
>> - the same process loads two copies of the GHC RTS as part of two
>> completely independent libraries? For added complications, imagine that
>> one of the libraries uses a different implementation instead (e.g. Hugs)
>> - one Haskell program loads several different plugins in a way that
>> allows Haskell values to pass across the plugin boundary
>> How do these scenarios work with use cases for <- like (a) Data.Unique and
>> (b) preventing multiple instantiation of a sub-library?
> That's a good question. But before you propose these scenarios, you must
> establish that they are sane for Haskell as it is today.
> In particular, would _local_ IORefs work correctly? After all, the memory
> allocator must be "global" in some sense. Could you be sure that different
> calls to newIORef returned separate IORefs?
Yes, I would expect that. Allocation areas propagate downwards from the OS
to the top-level of a process and then into dynamically loaded modules if
necessary. Any part of this puzzle that fails to keep them separate (in
some sense) is just broken.
> Perhaps this is the One True Global Scope: the scope in which refs from
> newIORef are guaranteed to be separate.
Every single call to newIORef, across the whole world, returns a different
ref. The "same" one as a previous one can only be returned once the old
one has become unused (and GCed).
> It's the scope in which values from newUnique are supposed to be
> different, and it would also be the scope in which top-level <- would be
> called at most once.
I don't really follow this. Do you mean the minimal such scope, or the
maximal such scope? The problem here is not about separate calls to
newIORef, it's about how many times an individual <- will be executed.
More information about the Haskell-Cafe