J'utilise QuickCheck v1. Voici un simple prop_xxx défini comme ci-dessous:Comment écrire une fonction à lancer quickCheck prop_xxx?
prop_foo :: (Num a) =>[a] -> Bool
prop_foo xs = (reverse.reverse) xs == id xs
Cela peut être testé en GHCi correctement: quickcheck prop_foo
Cependant, quand j'ai essayé d'envelopper l'appel dans une fonction comme:
f :: IO()
f = quickCheck prop_foo
Il a signalé l'erreur:
Ambiguous type variable `a' in the constraints:
`Num a' arising from a use of `prop_foo' at Foo.hs:147:15-22
`Arbitrary a'
arising from a use of `quickCheck' at Foo.hs:147:4-22
Probable fix: add a type signature that fixes these type variable(s)
Dois-je fournir lik quelque chose e
instance Arbitrary Xxx where
arbitrary = ...
coarbitrary c = ...
Merci beaucoup.
- Larry
Justement, c'est simplement que 'ghci' utilise par défaut' Integer'. C'est pourquoi 'ghci' ne se plaint pas, c'est bien sûr par commodité. Non? – Tarrasch