+{-# LANGUAGE CPP #-}
+
+#ifdef __GLASGOW_HASKELL__
+{-# LANGUAGE MagicHash, DeriveDataTypeable #-}
+#endif
+
-----------------------------------------------------------------------------
-- |
-- Module : Data.Unique
import GHC.Base
import GHC.Num
import GHC.Conc
+import Data.Typeable
#endif
-- | An abstract unique object. Objects of type 'Unique' may be
-- compared for equality and ordering and hashed into 'Int'.
-newtype Unique = Unique Integer deriving (Eq,Ord)
+newtype Unique = Unique Integer deriving (Eq,Ord
+#ifdef __GLASGOW_HASKELL__
+ ,Typeable
+#endif
+ )
uniqSource :: TVar Integer
uniqSource = unsafePerformIO (newTVarIO 0)
newUnique = atomically $ do
val <- readTVar uniqSource
let next = val+1
- writeTVar uniqSource $! val + 1
+ writeTVar uniqSource $! next
return (Unique next)
-- SDM (18/3/2010): changed from MVar to STM. This fixes