-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to check higher-kinded types with constrained element types #74
Comments
When compiling with GHC 8.5+, quickcheck-classes exposes all laws' foldableLaws :: forall proxy f.
(Foldable f, Eq1 f, Show1 f, Arbitrary1 f)
=> proxy f
-> Laws Becomes foldableLaws :: forall proxy f.
(Foldable f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a),
forall a. Arbitrary a => Arbitrary (f a))
=> proxy f
-> Laws |
This reminds me that we should do a release so the haddocks reflect this. |
ie as long as |
Ah, that explains the funny type error. I think
Accepting a |
Ah, yeah, Imessed up writing that proxy. The following typechecks for me with GHC 8.6.2: newtype Foo a = Foo a
deriving (Eq, Show, Foldable)
instance (Arbitrary a, Ord a) => Arbitrary (Foo a) where
arbitrary = fmap Foo arbitrary
foo :: Laws
foo = foldableLaws (Proxy @Foo) |
Not sure what I'm doing wrong then. For
I get
|
Oh, I guess it doesn't compile for me either. Something must've gone wrong with ghcid. |
I think the best we could do is allow users to plug in constraints, not sure if this works though: foldableLaws :: (Foldable f, forall x. (Eq x => Eq (f x), Show x => Show (f x)), forall x. (ctx x, Arbitrary x) => Arbitrary (f x))
=> Proxy ctx
-> Proxy f
-> Laws |
So, this seems to work in spirit, (it compiles and constraint resolution works as expected, if foldableLawsInternal doesn't test anything) but a problem arises internally. foldableLawsInternal :: forall proxy f ctx.
(Foldable f, forall a. Eq a => Eq (f a), forall a. Show a => Show (f a), forall a. (ctx a, Arbitrary a) => (ctx a, Arbitrary (f a)))
=> Proxy ctx
-> proxy f
-> Laws
foldableLawsInternal pc p = Laws "Foldable"
[ (,) "fold" $ property $ \(Apply (a :: f (Sum Integer))) ->
F.fold a == F.foldMap id a
, ...
] We get a bunch of type errors like so: src/Test/QuickCheck/Classes/Foldable.hs:115:18: error:
• Could not deduce: ctx x arising from a use of ‘property’
from the context: (Foldable f, forall a. Eq a => Eq (f a),
forall a. Show a => Show (f a),
forall a. (ctx a, Arbitrary a) => Arbitrary (f a))
bound by the type signature for:
foldableLawsInternal :: forall (proxy :: (* -> *) -> *) (f :: *
-> *) (ctx
:: *
-> Constraint).
(Foldable f, forall a. Eq a => Eq (f a),
forall a. Show a => Show (f a),
forall a. (ctx a, Arbitrary a) => Arbitrary (f
a)) =>
Proxy ctx -> proxy f -> Laws
at src/Test/QuickCheck/Classes/Foldable.hs:(107,1)-(113,33)
or from: Arbitrary x
bound by a quantified context
at src/Test/QuickCheck/Classes/Foldable.hs:1:1
• In the second argument of ‘($)’, namely
‘property
$ \ (Apply (a :: f (Sum Integer))) -> fold a == foldMap id a’
In the expression:
(,) "fold"
$ property
$ \ (Apply (a :: f (Sum Integer))) -> fold a == foldMap id a
In the second argument of ‘Laws’, namely
‘[(,) "fold"
$ property
$ \ (Apply (a :: f (Sum Integer))) -> fold a == foldMap id a,
(,) "foldMap"
$ property
$ \ (Apply (a :: f Integer)) (e :: QuadraticEquation)
-> let ... in foldMap f a == foldr (mappend . f) mempty a,
(,) "foldr"
$ property
$ \ (e :: LinearEquationTwo)
(z :: Integer)
(Apply (t :: f Integer))
-> let ... in foldr f z t == SG.appEndo (foldMap (Endo . f) t) z,
(,) "foldr'" (foldableFoldr' p), ....]’
• Relevant bindings include
pc :: Proxy ctx
(bound at src/Test/QuickCheck/Classes/Foldable.hs:114:22)
foldableLawsInternal :: Proxy ctx -> proxy f -> Laws
(bound at src/Test/QuickCheck/Classes/Foldable.hs:114:1)
|
115 | [ (,) "fold" $ property $ \(Apply (a :: f (SG.Sum Integer))) ->
|
That type error is a little confusing, since it refers to some type variable 'x' which doesn't exist, (might the renamer go from 'a' -> 'x'?), also the srcLoc of 1:1 is totally wrong. |
Since we're using the following instance of 'Testable':
the quantified constraint seems to be interfering with the |
That looks like a nice idea. No idea about how to implement it though. This is the first time I've seen |
@andrewthad is there anything here we could do with |
@sjakobi, this doesn't solve your issue, but will make your error messages make more sense when referencing the docs: quickcheck-classes 0.6.0.0 was just released to hackage. |
I just ran into this issue too. Types like |
I just ran into this too with Details
|
I think there's no reason to have quantified constraints here whatsoever, because they both overconstrain the functions and confuse the hell out of people 😅. It'd be perfectly fine to have
In the end, |
I'm currently trying to add some tests to the
multiset
package. In particular, I want to testMultiSet
'sFoldable
instance.It turns out that I can't currently use
foldableLaws
for this, as I can't define anArbitrary1
instance forMultiSet
. The problem is theOrd
constraint on the elements.Can you recommend a workaround or maybe offer a version of
foldableLaws
that doesn't requireArbitrary1
?The text was updated successfully, but these errors were encountered: