[Haskell-cafe] Quickcheck examples and Data.Word32

Nils Anders Danielsson nad at cs.chalmers.se
Thu Oct 27 15:11:50 EDT 2005


On Thu, 27 Oct 2005, Sebastian Sylvan <sebastian.sylvan at gmail.com> wrote:

> instance Arbitrary Word32 where
>   arbitrary = do c <- arbitrary :: Gen Integer
>                  return (fromIntegral c)

This definition will usually only generate very small or very large
Word32 values. The reason is the wrapping mentioned elsewhere and the
arbitrary definition for Integer:

  arbitrary = sized $ \n -> choose (-fromIntegral n,fromIntegral n)

You would need to manually ask for larger sizes (using
Test.QuickCheck.check with a suitable Config). If a uniform
distribution of Word32s is really needed then I would go with the
other definition.

-- 
/NAD



More information about the Haskell-Cafe mailing list