Skip to content

Commit

Permalink
Fix fromGFinite for product types
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim committed Jul 1, 2020
1 parent d97cdaf commit 493f506
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/System/Random/GFinite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ instance (GFinite a, GFinite b) => GFinite (a :*: b) where
{-# INLINE toGFinite #-}

fromGFinite (q :*: r) =
toInteger (gcardinality (proxy# :: Proxy# a) * Card (fromGFinite q)) + fromGFinite r
toInteger (gcardinality (proxy# :: Proxy# b) * Card (fromGFinite q)) + fromGFinite r
{-# INLINE fromGFinite #-}

instance Finite Void
Expand Down
5 changes: 4 additions & 1 deletion src/System/Random/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,13 @@ class UniformRange a where
-- >>> import GHC.Generics (Generic)
-- >>> import Data.Word (Word8)
-- >>> import System.Random.Stateful
-- >>> data Foo = Bar Word8 | Quux Word8 deriving (Show, Generic, Finite, UniformRange)
-- >>> gen <- newIOGenM (mkStdGen 42)
-- >>> data Foo = Bar Word8 | Quux Word8 deriving (Show, Generic, Finite, UniformRange)
-- >>> Control.Monad.replicateM 10 (uniformRM (Bar 100, Quux 150) gen)
-- [Bar 148,Bar 251,Bar 195,Quux 115,Quux 52,Bar 123,Bar 239,Bar 195,Quux 150,Quux 31]
-- >>> data Tuple = Tuple Bool Word8 deriving (Show, Generic, Finite, UniformRange)
-- >>> Control.Monad.replicateM 10 (uniformRM (Tuple False 100, Tuple True 150) gen)
-- [Tuple True 141,Tuple True 92,Tuple False 194,Tuple False 191,Tuple True 81,Tuple False 227,Tuple False 166,Tuple False 109,Tuple False 255,Tuple False 222]
--
-- @since 1.2.0
uniformRM :: StatefulGen g m => (a, a) -> g -> m a
Expand Down

0 comments on commit 493f506

Please sign in to comment.