[Haskell-cafe] Quick Question for QuickCheck2

austin seipp as at 0xff.ath.cx
Mon Aug 30 11:23:39 EDT 2010


You can create a wrapper with a newtype and then define an instance for that.

newtype Char2 = Char2 Char

instance Arbitrary Char2 where
  arbitrary = ...

You'll have to do some wrapping and unwrapping when calling your
properties to get/set the underlying Char, but this is probably the
easiest way to 'constrain' the possible arbitrary results when the
default instance for Char can be "too much."

On Mon, Aug 30, 2010 at 10:12 AM, Sebastian Höhn
<sebastian.hoehn at googlemail.com> wrote:
> Hello,
>
> perhaps I am just blind or is it a difficult issue: I would like to
> generate Char values in a given Range for QuickCheck2. There is this
> simple example from the haskell book:
>
> instance Arbitrary Char where
>   arbitrary = elements (['A'..'Z'] ++ ['a' .. 'z'] ++ " ~!@#$%^&*()")
>
> This does not work in QuickCheck2 since the instance is already
> defined. How do I achieve this behaviour in QC2?
>
> Thanks for helping.
>
> Sebastian
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
- Austin


More information about the Haskell-Cafe mailing list