Skip to content

Add StatefulGen instance for Gen #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Test/QuickCheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ module Test.QuickCheck

-- * The 'Gen' monad: combinators for building random generators
, Gen
#ifndef OLD_RANDOM
, QC(..)
#endif
-- ** Generator combinators
, choose
, chooseInt
Expand Down
14 changes: 13 additions & 1 deletion src/Test/QuickCheck/Gen.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE MultiParamTypeClasses #-}
#ifndef NO_ST_MONAD
{-# LANGUAGE Rank2Types #-}
#endif
Expand Down Expand Up @@ -42,7 +43,9 @@ import Data.Word
import Data.Int
import Data.Bits
import Control.Applicative

#ifndef OLD_RANDOM
import System.Random.Stateful
#endif
--------------------------------------------------------------------------
-- ** Generator type

Expand Down Expand Up @@ -92,6 +95,15 @@ instance MonadFix Gen where
let a = unGen (f a) r n
in a

#ifndef OLD_RANDOM
data QC = QC

instance StatefulGen QC Gen where
uniformWord32 QC = MkGen (\r _n -> runStateGen_ r uniformWord32)
uniformWord64 QC = MkGen (\r _n -> runStateGen_ r uniformWord64)
uniformShortByteString k QC =
MkGen (\r _n -> runStateGen_ r (uniformShortByteString k))
#endif
--------------------------------------------------------------------------
-- ** Primitive generator combinators

Expand Down