Commits

Bryan O'Sullivan committed 43e3e03

Add a Variate instance for Integer.

Comments (0)

Files changed (1)

Statistics/RandomVariate.hs

     --   statistical calculations that require non-zero values
     --   (e.g. uses of the 'log' function).
     --
-    -- * The range of random 'Integer' values is the same as for
+    -- * The range of random 'Integer' variates is the same as for
     --   'Int'.
     uniform :: Gen s -> ST s a
 
 instance Variate Int where
 #if WORD_SIZE_IN_BITS < 64
     uniform = f where f = uniform1 fromIntegral
-                      {-# INLINE f #-}
 #else
     uniform = f where f = uniform2 wordsTo64Bit
+#endif
                       {-# INLINE f #-}
-#endif
 
 instance Variate Word where
 #if WORD_SIZE_IN_BITS < 64
     uniform = f where f = uniform1 fromIntegral
-                      {-# INLINE f #-}
 #else
     uniform = f where f = uniform2 wordsTo64Bit
+#endif
                       {-# INLINE f #-}
-#endif
+
+instance Variate Integer where
+    uniform = f where f g = do
+                           u <- uniform g
+                           return $! fromIntegral (u :: Int)
+                      {-# INLINE f #-}
 
 instance (Variate a, Variate b) => Variate (a,b) where
     uniform = f where f g = (,) `fmap` uniform g `ap` uniform g