[Haskell-cafe] Quickcheck examples and Data.Word32

Joel Reymont joelr1 at gmail.com
Thu Oct 27 19:25:35 EDT 2005


This compiles:

instance (Typeable a, Arbitrary a, Typeable b, Arbitrary b,  
Convertible a b) => Arbitrary (Attr a b) where
     arbitrary = makeAttr `fmap` arbitrary
     coarbitrary a = error "Not implemented"

arbitraryProp :: forall a b.(Eq a, Packet b, Show a, Convertible a b,  
Arbitrary a, Arbitrary b) => Gen (Attr a b) -> Gen Prop
arbitraryProp attr = liftM2 (:=) attr arbitrary

     Joel

On Oct 28, 2005, at 12:13 AM, Joel Reymont wrote:

> Just one more question...
>
> data Prop = forall a b. (Eq a, Eq b, Show a, Packet b, Convertible  
> a b)
>     => Attr a b := a
>        deriving (Typeable)
>
> data Attr a b = Attr String
>     (a -> Dynamic, Dynamic -> Maybe a)
>     (a -> b, b -> a)
>
> makeAttr :: (Typeable a, Convertible a b) => String -> Attr a b
> makeAttr name = Attr name
>                 (toDyn, fromDynamic)
>                 (convert_AB, convert_BA)
>
> I can do this for Attr
>
> instance (Typeable a, Arbitrary a, Typeable b, Arbitrary b,  
> Convertible a b) => Arbitrary (Attr a b) where
>     arbitrary = makeAttr `fmap` arbitrary
>     coarbitrary a = error "Not implemented"
>
> How do I define an arbitrary prop, though? Following does not work:
>
> arbitraryProp :: forall a b.(Arbitrary a, Arbitrary b) => Attr a b - 
> > Gen Prop
> arbitraryProp  = arbitrary := arbitrary

--
http://wagerlabs.com/







More information about the Haskell-Cafe mailing list