[Haskell-cafe] Re: [Haskell] Top Level <-

Ashley Yakeley ashley at semantic.org
Sat Aug 30 08:27:43 EDT 2008

Ganesh Sittampalam wrote:
> How can they be the same unless the memory management system is broken? 
> I consider different pointers on different machines or in different 
> virtual address spaces different too; it's the fact that they don't 
> alias that matters.

But the actual pointer value might repeat.

>> every single call to newUnique across the whole world returns a 
>> different value, but internally they are Integers that might repeat.
> The thing about pointers is that they are managed by the standard 
> behaviour of memory allocation. This isn't true of Integers.

But it could be. A global variable allows us to do the same thing as the 
memory allocator, and allocate unique Integers just as the allocator 
allocates unique pointer values.

Now you can say that the same pointer value on different machines is 
different pointers; equally, you can say the same Integer in Unique on 
different machines is different Uniques: it's the fact that they don't 
alias that matters.

> In fact this point suggests an implementation for Data.Unique that 
> should actually be safe without global variables: just use IORefs for 
> the actual Unique values. IORefs already support Eq, as it happens. That 
> gives you process scope for free,

Isn't this rather ugly, though? We're using IORefs for something that 
doesn't involve reading or writing to them. Shouldn't there be a more 
general mechanism?

Ashley Yakeley

More information about the Haskell-Cafe mailing list