9
考慮下面的測試爲distributivity law between reverse and ++,哈斯克爾快速檢查最小的反例
import Test.QuickCheck
test :: [Int] -> [Int] -> Bool
test xs ys = reverse (xs ++ ys) == reverse xs ++ reverse ys
test2 :: (Eq a) => [a] -> [a] -> Bool
test2 xs ys = reverse (xs ++ ys) == reverse xs ++ reverse ys
注意有關Int
列出了
*Main> quickCheck test
*** Failed! Falsifiable (after 5 tests and 3 shrinks):
[1]
[0]
然而,測試equatable項目的列表,
*Main> quickCheck test2
+++ OK, passed 100 tests.
什麼讓第二次測試通過?
更新在與main = quickCheck test2
編譯曖昧類型變量的後續錯誤的提示問題(如答案已經描繪),
No instance for (Eq a0) arising from a use of `test2'
The type variable `a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)