A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://hackage.haskell.org/packages/archive/base/4.6.0.0/doc/html/src/Data-Unique.html below:

Data/Unique.hs




#ifdef __GLASGOW_HASKELL__

#endif















module Data.Unique (
   
   Unique,              
   newUnique,           
   hashUnique           
 ) where

import Prelude

import System.IO.Unsafe (unsafePerformIO)

#ifdef __GLASGOW_HASKELL__
import GHC.Base
import GHC.Num
import Data.Typeable
import Data.IORef
#endif



newtype Unique = Unique Integer deriving (Eq,Ord
#ifdef __GLASGOW_HASKELL__
   ,Typeable
#endif
   )

uniqSource :: IORef Integer
uniqSource = unsafePerformIO (newIORef 0)






newUnique :: IO Unique
newUnique = do
  r <- atomicModifyIORef uniqSource $ \x -> let z = x+1 in (z,z)
  r `seq` return (Unique r)



















hashUnique :: Unique -> Int
#if defined(__GLASGOW_HASKELL__)
hashUnique (Unique i) = I# (hashInteger i)
#else
hashUnique (Unique u) = fromInteger (u `mod` (toInteger (maxBound :: Int) + 1))
#endif

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4