Permalink
Browse files

Serial: remove custom Random interface (issue #1)

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...
1 parent 0d41a43 commit b0e46a77d685e1157523629b57166d5b1d4fb65b @kfish committed Aug 27, 2012
Showing with 3 additions and 12 deletions.
  1. +3 −12 Codec/Container/Ogg/Serial.hs
View
15 Codec/Container/Ogg/Serial.hs
@@ -43,18 +43,9 @@ demux = classify serialEq
-- | 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 = 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

0 comments on commit b0e46a7

Please sign in to comment.