我正在使用 QuickCheck v1。这是一个简单的 prop_xxx 定义如下:
prop_foo :: (Num a) =>[a] -> Bool
prop_foo xs = (reverse.reverse) xs == id xs
这可以在 GHCi 中正确测试:quickCheck prop_foo
但是,当我尝试将调用包装在如下函数中时:
f :: IO ()
f = quickCheck prop_foo
它报告了错误:
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)
我可以提供类似的东西吗
instance Arbitrary Xxx where
arbitrary = ...
coarbitrary c = ...
非常感谢。
——拉里