2011-04-21 53 views
1

我正在使用QuickCheck v1。下面是如下面所定义的简单prop_xxx:如何编写一个函数来激发quickCheck prop_xxx?

prop_foo :: (Num a) =>[a] -> Bool 
prop_foo xs = (reverse.reverse) xs == id xs 

这可以在GHCI正确地进行测试: 快速检查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) 

要我提供的东西LIK e

instance Arbitrary Xxx where 
    arbitrary  = ... 
    coarbitrary c = ... 

非常感谢。

- 拉里

回答

6

你必须给它一个单态类型签名,像

prop_foo :: [Int] -> Bool 


毕竟,问题是:在你的原始版本,a应哪种类型quickCheck选择测试功能? a = Inta = Double?还有别的吗?错误消息抱怨a不明确,即没有独特的选择。

+0

准确地说,只是'ghci'默认使用'Integer'。这就是为什么'ghci'没有抱怨,这当然是为了方便。没有? – Tarrasch 2011-04-21 08:39:04

相关问题