{-# LANGUAGE CPP #-}
#ifndef NO_ST_MONAD
{-# LANGUAGE Rank2Types #-}
#endif
-- | Test case generation.
--
-- __Note__: the contents of this module (except for the definition of
-- 'Gen') are re-exported by "Test.QuickCheck". You probably do not
-- need to import it directly.
module Test.QuickCheck.Gen where

--------------------------------------------------------------------------
-- imports

import System.Random
  ( Random
  , random
  , randomR
  , split
  )

import Control.Monad
  ( ap
  , replicateM
  , filterM
  )

import Control.Monad.Fix
  ( MonadFix(..) )

import Control.Applicative
  ( Applicative(..) )

import Test.QuickCheck.Random
import Data.List
import Data.Ord
import Data.Maybe

--------------------------------------------------------------------------
-- ** Generator type

-- | A generator for values of type @a@.
--
-- The third-party packages
-- <http://hackage.haskell.org/package/QuickCheck-GenT QuickCheck-GenT>
-- and
-- <http://hackage.haskell.org/package/quickcheck-transformer quickcheck-transformer>
-- provide monad transformer versions of @Gen@.
newtype Gen a = MkGen{
  Gen a -> QCGen -> Int -> a
unGen :: QCGen -> Int -> a -- ^ Run the generator on a particular seed.
                             -- If you just want to get a random value out, consider using 'generate'.
  }

instance Functor Gen where
  fmap :: (a -> b) -> Gen a -> Gen b
fmap f :: a -> b
f (MkGen h :: QCGen -> Int -> a
h) =
    (QCGen -> Int -> b) -> Gen b
forall a. (QCGen -> Int -> a) -> Gen a
MkGen (\r :: QCGen
r n :: Int
n -> a -> b
f (QCGen -> Int -> a
h QCGen
r Int
n))

instance Applicative Gen where
  pure :: a -> Gen a
pure  = a -> Gen a
forall (m :: * -> *) a. Monad m => a -> m a
return
  gf :: Gen (a -> b)
gf <*> :: Gen (a -> b) -> Gen a -> Gen b
<*> gx :: Gen a
gx = Gen (a -> b)
gf Gen (a -> b) -> ((a -> b) -> Gen b) -> Gen b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \f :: a -> b
f -> (a -> b) -> Gen a -> Gen b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Gen a
gx

instance Monad Gen where
  return :: a -> Gen a
return x :: a
x =
    (QCGen -> Int -> a) -> Gen a
forall a. (QCGen -> Int -> a) -> Gen a
MkGen (\_ _ -> a
x)

  MkGen m :: QCGen -> Int -> a
m >>= :: Gen a -> (a -> Gen b) -> Gen b
>>= k :: a -> Gen b
k =
    (QCGen -> Int -> b) -> Gen b
forall a. (QCGen -> Int -> a) -> Gen a
MkGen (\r :: QCGen
r n :: Int
n ->
      case QCGen -> (QCGen, QCGen)
forall g. RandomGen g => g -> (g, g)
split QCGen
r of
        (r1 :: QCGen
r1, r2 :: QCGen
r2) ->
          let MkGen m' :: QCGen -> Int -> b
m' = a -> Gen b
k (QCGen -> Int -> a
m QCGen
r1 Int
n)
          in QCGen -> Int -> b
m' QCGen
r2 Int
n
    )

instance MonadFix Gen where
  mfix :: (a -> Gen a) -> Gen a
mfix f :: a -> Gen a
f =
    (QCGen -> Int -> a) -> Gen a
forall a. (QCGen -> Int -> a) -> Gen a
MkGen ((QCGen -> Int -> a) -> Gen a) -> (QCGen -> Int -> a) -> Gen a
forall a b. (a -> b) -> a -> b
$ \r :: QCGen
r n :: Int
n ->
      let a :: a
a = Gen a -> QCGen -> Int -> a
forall a. Gen a -> QCGen -> Int -> a
unGen (a -> Gen a
f a
a) QCGen
r Int
n
      in a
a

--------------------------------------------------------------------------
-- ** Primitive generator combinators

-- | Modifies a generator using an integer seed.
variant :: Integral n => n -> Gen a -> Gen a
variant :: n -> Gen a -> Gen a
variant k :: n
k (MkGen g :: QCGen -> Int -> a
g) = (QCGen -> Int -> a) -> Gen a
forall a. (QCGen -> Int -> a) -> Gen a
MkGen (\r :: QCGen
r n :: Int
n -> QCGen -> Int -> a
g (Integer -> QCGen -> QCGen
forall a. Splittable a => Integer -> a -> a
integerVariant (n -> Integer
forall a. Integral a => a -> Integer
toInteger n
k) (QCGen -> QCGen) -> QCGen -> QCGen
forall a b. (a -> b) -> a -> b
$! QCGen
r) Int
n)

-- | Used to construct generators that depend on the size parameter.
--
-- For example, 'listOf', which uses the size parameter as an upper bound on
-- length of lists it generates, can be defined like this:
--
-- > listOf :: Gen a -> Gen [a]
-- > listOf gen = sized $ \n ->
-- >   do k <- choose (0,n)
-- >      vectorOf k gen
--
-- You can also do this using 'getSize'.
sized :: (Int -> Gen a) -> Gen a
sized :: (Int -> Gen a) -> Gen a
sized f :: Int -> Gen a
f = (QCGen -> Int -> a) -> Gen a
forall a. (QCGen -> Int -> a) -> Gen a
MkGen (\r :: QCGen
r n :: Int
n -> let MkGen m :: QCGen -> Int -> a
m = Int -> Gen a
f Int
n in QCGen -> Int -> a
m QCGen
r Int
n)

-- | Returns the size parameter. Used to construct generators that depend on
-- the size parameter.
--
-- For example, 'listOf', which uses the size parameter as an upper bound on
-- length of lists it generates, can be defined like this:
--
-- > listOf :: Gen a -> Gen [a]
-- > listOf gen = do
-- >   n <- getSize
-- >   k <- choose (0,n)
-- >   vectorOf k gen
--
-- You can also do this using 'sized'.
getSize :: Gen Int
getSize :: Gen Int
getSize = (Int -> Gen Int) -> Gen Int
forall a. (Int -> Gen a) -> Gen a
sized Int -> Gen Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure

-- | Overrides the size parameter. Returns a generator which uses
-- the given size instead of the runtime-size parameter.
resize :: Int -> Gen a -> Gen a
resize :: Int -> Gen a -> Gen a
resize n :: Int
n _ | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< 0 = [Char] -> Gen a
forall a. HasCallStack => [Char] -> a
error "Test.QuickCheck.resize: negative size"
resize n :: Int
n (MkGen g :: QCGen -> Int -> a
g) = (QCGen -> Int -> a) -> Gen a
forall a. (QCGen -> Int -> a) -> Gen a
MkGen (\r :: QCGen
r _ -> QCGen -> Int -> a
g QCGen
r Int
n)

-- | Adjust the size parameter, by transforming it with the given
-- function.
scale :: (Int -> Int) -> Gen a -> Gen a
scale :: (Int -> Int) -> Gen a -> Gen a
scale f :: Int -> Int
f g :: Gen a
g = (Int -> Gen a) -> Gen a
forall a. (Int -> Gen a) -> Gen a
sized (\n :: Int
n -> Int -> Gen a -> Gen a
forall a. Int -> Gen a -> Gen a
resize (Int -> Int
f Int
n) Gen a
g)

-- | Generates a random element in the given inclusive range.
choose :: Random a => (a,a) -> Gen a
choose :: (a, a) -> Gen a
choose rng :: (a, a)
rng = (QCGen -> Int -> a) -> Gen a
forall a. (QCGen -> Int -> a) -> Gen a
MkGen (\r :: QCGen
r _ -> let (x :: a
x,_) = (a, a) -> QCGen -> (a, QCGen)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a, a)
rng QCGen
r in a
x)

-- | Generates a random element over the natural range of `a`.
chooseAny :: Random a => Gen a
chooseAny :: Gen a
chooseAny = (QCGen -> Int -> a) -> Gen a
forall a. (QCGen -> Int -> a) -> Gen a
MkGen (\r :: QCGen
r _ -> let (x :: a
x,_) = QCGen -> (a, QCGen)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random QCGen
r in a
x)

-- | Run a generator. The size passed to the generator is always 30;
-- if you want another size then you should explicitly use 'resize'.
generate :: Gen a -> IO a
generate :: Gen a -> IO a
generate (MkGen g :: QCGen -> Int -> a
g) =
  do QCGen
r <- IO QCGen
newQCGen
     a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (QCGen -> Int -> a
g QCGen
r 30)

-- | Generates some example values.
sample' :: Gen a -> IO [a]
sample' :: Gen a -> IO [a]
sample' g :: Gen a
g =
  Gen [a] -> IO [a]
forall a. Gen a -> IO a
generate ([Gen a] -> Gen [a]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [ Int -> Gen a -> Gen a
forall a. Int -> Gen a -> Gen a
resize Int
n Gen a
g | Int
n <- [0,2..20] ])

-- | Generates some example values and prints them to 'stdout'.
sample :: Show a => Gen a -> IO ()
sample :: Gen a -> IO ()
sample g :: Gen a
g =
  do [a]
cases <- Gen a -> IO [a]
forall a. Gen a -> IO [a]
sample' Gen a
g
     (a -> IO ()) -> [a] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ a -> IO ()
forall a. Show a => a -> IO ()
print [a]
cases

--------------------------------------------------------------------------
-- ** Common generator combinators

-- | Generates a value that satisfies a predicate.
suchThat :: Gen a -> (a -> Bool) -> Gen a
gen :: Gen a
gen suchThat :: Gen a -> (a -> Bool) -> Gen a
`suchThat` p :: a -> Bool
p =
  do Maybe a
mx <- Gen a
gen Gen a -> (a -> Bool) -> Gen (Maybe a)
forall a. Gen a -> (a -> Bool) -> Gen (Maybe a)
`suchThatMaybe` a -> Bool
p
     case Maybe a
mx of
       Just x :: a
x  -> a -> Gen a
forall (m :: * -> *) a. Monad m => a -> m a
return a
x
       Nothing -> (Int -> Gen a) -> Gen a
forall a. (Int -> Gen a) -> Gen a
sized (\n :: Int
n -> Int -> Gen a -> Gen a
forall a. Int -> Gen a -> Gen a
resize (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
+1) (Gen a
gen Gen a -> (a -> Bool) -> Gen a
forall a. Gen a -> (a -> Bool) -> Gen a
`suchThat` a -> Bool
p))

-- | Generates a value for which the given function returns a 'Just', and then
-- applies the function.
suchThatMap :: Gen a -> (a -> Maybe b) -> Gen b
gen :: Gen a
gen suchThatMap :: Gen a -> (a -> Maybe b) -> Gen b
`suchThatMap` f :: a -> Maybe b
f =
  (Maybe b -> b) -> Gen (Maybe b) -> Gen b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Maybe b -> b
forall a. HasCallStack => Maybe a -> a
fromJust (Gen (Maybe b) -> Gen b) -> Gen (Maybe b) -> Gen b
forall a b. (a -> b) -> a -> b
$ (a -> Maybe b) -> Gen a -> Gen (Maybe b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Maybe b
f Gen a
gen Gen (Maybe b) -> (Maybe b -> Bool) -> Gen (Maybe b)
forall a. Gen a -> (a -> Bool) -> Gen a
`suchThat` Maybe b -> Bool
forall a. Maybe a -> Bool
isJust

-- | Tries to generate a value that satisfies a predicate.
-- If it fails to do so after enough attempts, returns @Nothing@.
suchThatMaybe :: Gen a -> (a -> Bool) -> Gen (Maybe a)
gen :: Gen a
gen suchThatMaybe :: Gen a -> (a -> Bool) -> Gen (Maybe a)
`suchThatMaybe` p :: a -> Bool
p = (Int -> Gen (Maybe a)) -> Gen (Maybe a)
forall a. (Int -> Gen a) -> Gen a
sized (\n :: Int
n -> Int -> Int -> Gen (Maybe a)
try Int
n (2Int -> Int -> Int
forall a. Num a => a -> a -> a
*Int
n))
 where
  try :: Int -> Int -> Gen (Maybe a)
try m :: Int
m n :: Int
n
    | Int
m Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
n = Maybe a -> Gen (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing
    | Bool
otherwise = do
        a
x <- Int -> Gen a -> Gen a
forall a. Int -> Gen a -> Gen a
resize Int
m Gen a
gen
        if a -> Bool
p a
x then Maybe a -> Gen (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> Maybe a
forall a. a -> Maybe a
Just a
x) else Int -> Int -> Gen (Maybe a)
try (Int
mInt -> Int -> Int
forall a. Num a => a -> a -> a
+1) Int
n

-- | Randomly uses one of the given generators. The input list
-- must be non-empty.
oneof :: [Gen a] -> Gen a
oneof :: [Gen a] -> Gen a
oneof [] = [Char] -> Gen a
forall a. HasCallStack => [Char] -> a
error "QuickCheck.oneof used with empty list"
oneof gs :: [Gen a]
gs = (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (0,[Gen a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Gen a]
gs Int -> Int -> Int
forall a. Num a => a -> a -> a
- 1) Gen Int -> (Int -> Gen a) -> Gen a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ([Gen a]
gs [Gen a] -> Int -> Gen a
forall a. [a] -> Int -> a
!!)

-- | Chooses one of the given generators, with a weighted random distribution.
-- The input list must be non-empty.
frequency :: [(Int, Gen a)] -> Gen a
frequency :: [(Int, Gen a)] -> Gen a
frequency [] = [Char] -> Gen a
forall a. HasCallStack => [Char] -> a
error "QuickCheck.frequency used with empty list"
frequency xs :: [(Int, Gen a)]
xs
  | (Int -> Bool) -> [Int] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< 0) (((Int, Gen a) -> Int) -> [(Int, Gen a)] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (Int, Gen a) -> Int
forall a b. (a, b) -> a
fst [(Int, Gen a)]
xs) =
    [Char] -> Gen a
forall a. HasCallStack => [Char] -> a
error "QuickCheck.frequency: negative weight"
  | (Int -> Bool) -> [Int] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== 0) (((Int, Gen a) -> Int) -> [(Int, Gen a)] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (Int, Gen a) -> Int
forall a b. (a, b) -> a
fst [(Int, Gen a)]
xs) =
    [Char] -> Gen a
forall a. HasCallStack => [Char] -> a
error "QuickCheck.frequency: all weights were zero"
frequency xs0 :: [(Int, Gen a)]
xs0 = (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (1, Int
tot) Gen Int -> (Int -> Gen a) -> Gen a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Int -> [(Int, Gen a)] -> Gen a
forall t p. (Ord t, Num t) => t -> [(t, p)] -> p
`pick` [(Int, Gen a)]
xs0)
 where
  tot :: Int
tot = [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum (((Int, Gen a) -> Int) -> [(Int, Gen a)] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (Int, Gen a) -> Int
forall a b. (a, b) -> a
fst [(Int, Gen a)]
xs0)

  pick :: t -> [(t, p)] -> p
pick n :: t
n ((k :: t
k,x :: p
x):xs :: [(t, p)]
xs)
    | t
n t -> t -> Bool
forall a. Ord a => a -> a -> Bool
<= t
k    = p
x
    | Bool
otherwise = t -> [(t, p)] -> p
pick (t
nt -> t -> t
forall a. Num a => a -> a -> a
-t
k) [(t, p)]
xs
  pick _ _  = [Char] -> p
forall a. HasCallStack => [Char] -> a
error "QuickCheck.pick used with empty list"

-- | Generates one of the given values. The input list must be non-empty.
elements :: [a] -> Gen a
elements :: [a] -> Gen a
elements [] = [Char] -> Gen a
forall a. HasCallStack => [Char] -> a
error "QuickCheck.elements used with empty list"
elements xs :: [a]
xs = ([a]
xs [a] -> Int -> a
forall a. [a] -> Int -> a
!!) (Int -> a) -> Gen Int -> Gen a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (0, [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
xs Int -> Int -> Int
forall a. Num a => a -> a -> a
- 1)

-- | Generates a random subsequence of the given list.
sublistOf :: [a] -> Gen [a]
sublistOf :: [a] -> Gen [a]
sublistOf xs :: [a]
xs = (a -> Gen Bool) -> [a] -> Gen [a]
forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterM (\_ -> (Bool, Bool) -> Gen Bool
forall a. Random a => (a, a) -> Gen a
choose (Bool
False, Bool
True)) [a]
xs

-- | Generates a random permutation of the given list.
shuffle :: [a] -> Gen [a]
shuffle :: [a] -> Gen [a]
shuffle xs :: [a]
xs = do
  [Int]
ns <- Int -> Gen Int -> Gen [Int]
forall a. Int -> Gen a -> Gen [a]
vectorOf ([a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
xs) ((Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (Int
forall a. Bounded a => a
minBound :: Int, Int
forall a. Bounded a => a
maxBound))
  [a] -> Gen [a]
forall (m :: * -> *) a. Monad m => a -> m a
return (((Int, a) -> a) -> [(Int, a)] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (Int, a) -> a
forall a b. (a, b) -> b
snd (((Int, a) -> (Int, a) -> Ordering) -> [(Int, a)] -> [(Int, a)]
forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (((Int, a) -> Int) -> (Int, a) -> (Int, a) -> Ordering
forall a b. Ord a => (b -> a) -> b -> b -> Ordering
comparing (Int, a) -> Int
forall a b. (a, b) -> a
fst) ([Int] -> [a] -> [(Int, a)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int]
ns [a]
xs)))

-- | Takes a list of elements of increasing size, and chooses
-- among an initial segment of the list. The size of this initial
-- segment increases with the size parameter.
-- The input list must be non-empty.
growingElements :: [a] -> Gen a
growingElements :: [a] -> Gen a
growingElements [] = [Char] -> Gen a
forall a. HasCallStack => [Char] -> a
error "QuickCheck.growingElements used with empty list"
growingElements xs :: [a]
xs = (Int -> Gen a) -> Gen a
forall a. (Int -> Gen a) -> Gen a
sized ((Int -> Gen a) -> Gen a) -> (Int -> Gen a) -> Gen a
forall a b. (a -> b) -> a -> b
$ \n :: Int
n -> [a] -> Gen a
forall a. [a] -> Gen a
elements (Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
take (1 Int -> Int -> Int
forall a. Ord a => a -> a -> a
`max` Int -> Int
size Int
n) [a]
xs)
  where
   k :: Int
k        = [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
xs
   mx :: Int
mx       = 100
   log' :: Int -> Int
log'     = Double -> Int
forall a b. (RealFrac a, Integral b) => a -> b
round (Double -> Int) -> (Int -> Double) -> Int -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Double
forall a. Floating a => a -> a
log (Double -> Double) -> (Int -> Double) -> Int -> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Double
toDouble
   size :: Int -> Int
size n :: Int
n   = (Int -> Int
log' Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
+ 1) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
k Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int -> Int
log' Int
mx
   toDouble :: Int -> Double
toDouble = Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral :: Int -> Double

{- WAS:
growingElements xs = sized $ \n -> elements (take (1 `max` (n * k `div` 100)) xs)
 where
  k = length xs
-}

-- | Generates a list of random length. The maximum length depends on the
-- size parameter.
listOf :: Gen a -> Gen [a]
listOf :: Gen a -> Gen [a]
listOf gen :: Gen a
gen = (Int -> Gen [a]) -> Gen [a]
forall a. (Int -> Gen a) -> Gen a
sized ((Int -> Gen [a]) -> Gen [a]) -> (Int -> Gen [a]) -> Gen [a]
forall a b. (a -> b) -> a -> b
$ \n :: Int
n ->
  do Int
k <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (0,Int
n)
     Int -> Gen a -> Gen [a]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
k Gen a
gen

-- | Generates a non-empty list of random length. The maximum length
-- depends on the size parameter.
listOf1 :: Gen a -> Gen [a]
listOf1 :: Gen a -> Gen [a]
listOf1 gen :: Gen a
gen = (Int -> Gen [a]) -> Gen [a]
forall a. (Int -> Gen a) -> Gen a
sized ((Int -> Gen [a]) -> Gen [a]) -> (Int -> Gen [a]) -> Gen [a]
forall a b. (a -> b) -> a -> b
$ \n :: Int
n ->
  do Int
k <- (Int, Int) -> Gen Int
forall a. Random a => (a, a) -> Gen a
choose (1,1 Int -> Int -> Int
forall a. Ord a => a -> a -> a
`max` Int
n)
     Int -> Gen a -> Gen [a]
forall a. Int -> Gen a -> Gen [a]
vectorOf Int
k Gen a
gen

-- | Generates a list of the given length.
vectorOf :: Int -> Gen a -> Gen [a]
vectorOf :: Int -> Gen a -> Gen [a]
vectorOf = Int -> Gen a -> Gen [a]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM

-- | Generates an infinite list.
infiniteListOf :: Gen a -> Gen [a]
infiniteListOf :: Gen a -> Gen [a]
infiniteListOf gen :: Gen a
gen = [Gen a] -> Gen [a]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence (Gen a -> [Gen a]
forall a. a -> [a]
repeat Gen a
gen)

--------------------------------------------------------------------------
-- the end.