
ajb@spamcop.net wrote:
G'day all.
Quoting Sebastian Fischer
: I have wrapped up (a tiny subset of) GHC's uniques into the package `uniqueid` and put it on Hackage:
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/uniqueid
First off, thanks for this.
The main difference is due to my fear of depending on the foreign function `genSymZh` which I replaced by a global counting IORef.
Why not depend on this instead?
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/value-supply
Looking at the code for this, I'm somewhat suspicious that it actually works with GHC: -- The extra argument to ``gen'' is passed because without -- it Hugs spots that the recursive calls are the same but does -- not know that unsafePerformIO is unsafe. where gen _ r = Node { supplyValue = unsafePerformIO (genSym r), supplyLeft = gen False r, supplyRight = gen True r } even if that extra Bool argument is enough to fool Hugs, I wouldn't count on it being enough to fool GHC -O2! You probably want to use unsafeInterleaveIO like we do in GHC's UniqSupply library. Also, I'd replace the MVar with an IORef and use atomicModifyIORef for speed. Cheers, Simon