[Haskell-cafe] Quickcheck examples and Data.Word32

Joel Reymont joelr1 at gmail.com
Thu Oct 27 13:13:59 EDT 2005


Is there a way to squeeze this boilerplate code?

class Arbitrary
instance Arbitrary Word16 where
     arbitrary = do let mx,mn :: Integer
                        mx = fromIntegral (maxBound :: Word16)
                        mn = fromIntegral (minBound :: Word16)
                    c <- choose (mx, mn)
                    return (fromIntegral c)
     coarbitrary a = error "Not implemented"

instance Arbitrary Word32 where
     arbitrary = do let mx,mn :: Integer
                        mx = fromIntegral (maxBound :: Word32)
                        mn = fromIntegral (minBound :: Word32)
                    c <- choose (mx, mn)
                    return (fromIntegral c)
     coarbitrary a = error "Not implemented"

instance Arbitrary Word64 where
     arbitrary = do let mx,mn :: Integer
                        mx = fromIntegral (maxBound :: Word64)
                        mn = fromIntegral (minBound :: Word64)
                    c <- choose (mx, mn)
                    return (fromIntegral c)
     coarbitrary a = error "Not implemented"


On Oct 27, 2005, at 5:35 PM, Sebastian Sylvan wrote:

> instance Arbitrary Word32 where
>  arbitrary = do let mx,mn :: Integer
>                          mx = fromIntegral (maxBound :: Word32)
>                          mn = fromIntegral (minBound :: Word32)
>                      c <- choose (mx, mn)
>                      return (fromIntegral c)
>

--
http://wagerlabs.com/







More information about the Haskell-Cafe mailing list