Rozważmy następujące testy dla distributivity law between reverse and ++,Haskell QuickCheck minimalny licznik przykład
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
Uwaga na listach Int
że
*Main> quickCheck test
*** Failed! Falsifiable (after 5 tests and 3 shrinks):
[1]
[0]
Jednakże test na listach equatable przedmiotów,
*Main> quickCheck test2
+++ OK, passed 100 tests.
Co sprawia, że drugi test przechodzi?
Aktualizacja Na kompilacji z main = quickCheck test2
, kolejny błąd na zmienną typu niejednoznacznej wskazówki problem (jak już przedstawiono w odpowiedzi),
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)