[Haskell-cafe] Re: Generating repeatable arbitrary values with QuickCheck 2

Stefan Holdermans stefan at cs.uu.nl
Fri Feb 5 08:39:55 EST 2010


Martijn,

Ryan wrote:

>> Unfortunately, this makes things like
>>> infinite_xs <- sequence (repeat arbitrary)
>> no longer work, since the state never comes out the other side.

You replied:

> You're asking to execute an infinite number of monadic actions. How  
> can this ever terminate at all?

There is this thing called lazy evaluation, you know. ;-)

Try for yourself:

   import System.Random
   import Test.QuickCheck

   foo :: Gen [Int]
   foo = do
     ns <- sequence (repeat arbitrary)
     return (take 5 ns)

   main ::	IO ()
   main = do
     stdGen <- newStdGen
     print (generate 42 stdGen foo)

Cheers,

   Stefan


More information about the Haskell-Cafe mailing list