I am testing a function called extractions that operates over any list.
我正在测试一个名为提取的函数,它可以在任何列表上运行。
extractions :: [a] -> [(a,[a])]
extractions [] = []
extractions l = extract l []
where extract [] _ = []
extract (x:xs) prev = (x, prev++xs) : extract xs (x : prev)
I want to test it, for example, with
我想测试它,例如,用
import Test.QuickCheck.Batch
prop_len l = length l == length (extractions l)
main = runTests "extractions" defOpt [run prop_len]
But this won't compile; I have to supply a type either for run
or prop_len
, because QuickCheck can't generate [a]
, it has to generate something concrete. So I chose Int
:
但这不会编译;我必须为run或prop_len提供一个类型,因为QuickCheck不能生成[a],它必须生成具体的东西。所以我选择了Int:
main = runTests "extractions" defOpt [r prop_len]
where r = run :: ([Int] -> Bool) -> TestOptions -> IO TestResult
Is there any way to get QuickCheck to choose a
for me instead of having it specified in the type of run
?
有没有办法让QuickCheck为我选择一个而不是在运行类型中指定它?
1 个解决方案
#1
7
The quickcheck manual says "no":
quickcheck手册说“不”:
Properties must have monomorphic types. `Polymorphic' properties, such as the one above, must be restricted to a particular type to be used for testing. It is convenient to do so by stating the types of one or more arguments in a
属性必须具有单形类型。 “多态”属性(例如上面的属性)必须限制为用于测试的特定类型。通过在a中声明一个或多个参数的类型来方便
where types = (x1 :: t1, x2 :: t2, ...)
其中types =(x1 :: t1,x2 :: t2,...)
clause...
#1
7
The quickcheck manual says "no":
quickcheck手册说“不”:
Properties must have monomorphic types. `Polymorphic' properties, such as the one above, must be restricted to a particular type to be used for testing. It is convenient to do so by stating the types of one or more arguments in a
属性必须具有单形类型。 “多态”属性(例如上面的属性)必须限制为用于测试的特定类型。通过在a中声明一个或多个参数的类型来方便
where types = (x1 :: t1, x2 :: t2, ...)
其中types =(x1 :: t1,x2 :: t2,...)
clause...