[Haskell-cafe] Hspec + QuickCheck passing type
Will Yager
will.yager at gmail.com
Mon Mar 28 18:55:31 UTC 2016
I would recommend using http://hackage.haskell.org/package/base-4.8.2.0/docs/Prelude.html#v:asTypeOf
And passing a dummy variable of the correct type.
-Will
> On Mar 28, 2016, at 12:53, Martijn Rijkeboer <haskell at bunix.org> wrote:
>
> Hi,
>
> I'm writing the following Hspec + QuickCheck test for some type:
>
> context "Type1" $
> it "decode inverses encode" $ property $
> \x -> (decode . encode) x == Right (x::Type1)
>
>
> However, I have a number of these types, and I could write the same test
> for every type, but that isn't very DRY. Therefore I would like to put the
> test in a function and call that function for every type. Something like
> the following:
>
> typeTest name = do
> context name $
> it "decode inverses encode" $ property $
> \x -> (decode . encode) x == Right x
>
>
> Unfortunately this doesn't work, since QuickCheck doesn't know which
> Arbitrary instance to use. How can I pass the type, e.g. x::Type1, to
> this function so QuickCheck knows what Arbitrary instance to use?
>
> Kind regards,
>
>
> Martijn Rijkeboer
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list