From 798a8f37e17474355b4bf7419e40cc0b994ad6c0 Mon Sep 17 00:00:00 2001 From: Alexey Kuleshevich Date: Sun, 25 Jul 2021 22:20:16 +0300 Subject: [PATCH 1/2] Add StatefulGen instance for Gen --- src/Test/QuickCheck.hs | 1 + src/Test/QuickCheck/Gen.hs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Test/QuickCheck.hs b/src/Test/QuickCheck.hs index 405ced04..2376f53d 100644 --- a/src/Test/QuickCheck.hs +++ b/src/Test/QuickCheck.hs @@ -93,6 +93,7 @@ module Test.QuickCheck -- * The 'Gen' monad: combinators for building random generators , Gen + , QC(..) -- ** Generator combinators , choose , chooseInt diff --git a/src/Test/QuickCheck/Gen.hs b/src/Test/QuickCheck/Gen.hs index ee1507a7..537c5a10 100644 --- a/src/Test/QuickCheck/Gen.hs +++ b/src/Test/QuickCheck/Gen.hs @@ -1,4 +1,5 @@ {-# LANGUAGE CPP #-} +{-# LANGUAGE MultiParamTypeClasses #-} #ifndef NO_ST_MONAD {-# LANGUAGE Rank2Types #-} #endif @@ -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 @@ -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 From 79115356c56753894516e6943394ee3806b7974c Mon Sep 17 00:00:00 2001 From: Alexey Kuleshevich Date: Sun, 25 Jul 2021 22:42:07 +0300 Subject: [PATCH 2/2] Forgot some CPP --- src/Test/QuickCheck.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Test/QuickCheck.hs b/src/Test/QuickCheck.hs index 2376f53d..1c91a681 100644 --- a/src/Test/QuickCheck.hs +++ b/src/Test/QuickCheck.hs @@ -93,7 +93,9 @@ module Test.QuickCheck -- * The 'Gen' monad: combinators for building random generators , Gen +#ifndef OLD_RANDOM , QC(..) +#endif -- ** Generator combinators , choose , chooseInt