[Haskell-cafe] Test.QuickCheck.Gen

Tony Morris tmorris at tmorris.net
Thu May 1 17:18:50 EDT 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I am trying to understand the QuickCheck source in a bit of depth and
I have noted that a Gen x is a function Int -> StdGen -> x, however,
some of the combinators can at times, fail to ever produce a result by
throwing an error. I include an example using ghci:

*Test.QuickCheck> (f 0 (mkStdGen 0)) :: Int
*** Exception: Prelude.(!!): negative index

It seems this can be alleviated by changing Gen x to Int -> StdGen ->
Maybe x and having the generator produce Nothing when a combinator
fails. However, now the function promote cannot be written (I have
tried and run into the conundrum of writing the function (a -> Maybe
b) -> Maybe (a -> b)), which is used to generate functions. So, I'm
caught on the fence about whether there is a possible improvement here
(for example, should the elements function throw the error?), or if
the current scenario is acceptable.

I'm seeking comments about this, thanks!

- --
Tony Morris
http://tmorris.net/

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIGjO6mnpgrYe6r60RAtohAKCBsl1lHxuNrBaLHuqwCN58PBHCIACbBALk
YWkBkw9o9NUQbr+lgo0rXE0=
=JQlH
-----END PGP SIGNATURE-----



More information about the Haskell-Cafe mailing list