A common technique (at least until something like my suggested
Unique module becomes standard . . .) is to use unsafePerformIO
to create an MVar, and generate unique numbers from that MVar.
This technique fails for ghc-4.08 (binary release) using
optimisation options -O -O2-for-C on Linux, as the attached
files show. The output from obj should be
[0,1,2,3,4,5,6]. It looks as if GHC is cloning the MVar . . .
And yes I know unsafePerformIO is an invention of the Devil
sent to tempt functional programmers, but how else am I to
write this function?
> /home/ger/ghc-4.08-binary/bin/ghc -o obj Obj.hs TestObj.hs -package concurrent
>-package lang -O -O2-for-C
> ./obj
[0,0,0,0,0,0,0]
[ By the way Christoph, this is the bug that was causing HTk
to crash. And boy, was it boring finding it . . . ]
Obj.hs
TestObj.hs