Skip to content

Commit

Permalink
Serial: remove custom Random interface (issue #1)
Browse files Browse the repository at this point in the history
System.Random in ghc-7.x.y contains an instance for Word32, and
the Serial module fails to build with ghc-7.4.x due to duplicate
instance declarations.

There is no need for the custom instance, so remove it and use
randomR directly.

Tested-with: ghc-7.0.3, ghc-7.2.1, ghc-7.4.2, ghc-7.6.0.20120810
  • Loading branch information
kfish committed Aug 27, 2012
1 parent 0d41a43 commit b0e46a7
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions Codec/Container/Ogg/Serial.hs
Expand Up @@ -43,18 +43,9 @@ demux = classify serialEq
-- | Generate a serial number -- | Generate a serial number
-- --


-- Make a special instance of Random for Serial that does not include
-- 0xffffffff, as this value is treated specailly by libogg
instance Random Serial where
randomR = integralRandomR
random = randomR (0,0xffffffff-1)

integralRandomR :: (Integral a, RandomGen g) => (a,a) -> g -> (a,g)
integralRandomR (a,b) g = case randomR (fromIntegral a :: Integer,
fromIntegral b :: Integer) g of
(x,g') -> (fromIntegral x, g')

genSerial :: IO Serial genSerial :: IO Serial
genSerial = do genSerial = do
serialno <- getStdRandom random -- Randomly generate a Serial that does not equal
-- 0xffffffff, as this value is treated specailly by libogg
serialno <- getStdRandom (randomR (0,0xffffffff-1))
return serialno return serialno

0 comments on commit b0e46a7

Please sign in to comment.