[Haskell-cafe] How to choose an arbitrary Arbitrary?

Bas van Dijk v.dijk.bas at gmail.com
Thu Dec 18 04:24:31 EST 2008


On Wed, Dec 17, 2008 at 11:05 PM, Ryan Ingram <ryani.spam at gmail.com> wrote:
> ...It's possible to extend this idea and generate an "arbitrary arbitrary"...

Thanks for your thorough answer.

I like the SomeArbitrary idea. I see it's easy to also sample[1] SomeArbitrary.
You do need to add a 'Show' constraint to the existential 'a' in SomeArbitrary.

samplesSomeArbitrary :: IO ()
samplesSomeArbitrary = mapM_ f =<< sample' arbitrary
    where
      f (SomeArbitrary a) = sample (arbitrary `asTypeOf` gen a)
          where
            gen :: a -> Gen a
            gen _ = undefined

Thanks,

Bas

[1] sample: http://hackage.haskell.org/packages/archive/QuickCheck/2.1.0.1/doc/html/Test-QuickCheck.html#v%3Asample


More information about the Haskell-Cafe mailing list