[Haskell-cafe] How unique is Unique

Simon Marlow marlowsd at gmail.com
Fri May 27 15:44:57 CEST 2011


On 27/05/2011 13:40, Emil Axelsson wrote:
> 2011-05-27 13:12, Simon Marlow skrev:
>> On 27/05/2011 08:35, Emil Axelsson wrote:
>>> Hello!
>>>
>>> Lacking a proper blog, I've written some notes about Data.Unique here:
>>>
>>> http://community.haskell.org/~emax/darcs/MoreUnique/
>>>
>>> This describes a real problem that makes Data.Unique unsuitable for
>>> implementing observable sharing.
>>>
>>> The document also proposes a solution that uses time stamps to generate
>>> symbols that are "more unique".
>>>
>>> Does anyone have any comments on the proposed solution? Are there any
>>> alternatives available?
>>
>> This has nothing to do with Unique, you are simply using unsafePerformIO
>> in an unsafe way. It is called unsafePerformIO for a reason :-)
>
> Right, I wasn't suggesting this is a bug in Data.Unique. It's just that
> I need something different. I've added a note about this on the post.
>
> Note that I am planning to wrap all this in a safe interface. So using
> unsafePerformIO should be fine in this case, as long as Unique symbols
> survive GHCi reloads.

Oh, I missed the bit about observable sharing, sorry.  Anyway, I think 
the explanation for what you're seeing is that :r resets the Unique 
counter, because the counter is a CAF in Data.Unique and :r resets all 
CAFs.  This wouldn't happen in a compiled program, or even using 
runhaskell, it's only :r that triggers resetting of CAFs.  Still, to use 
a phrase coined by Lennart Augustsson, "the ice is thin here".

Cheers,
	Simon



More information about the Haskell-Cafe mailing list