Thanks for the video! I'm trying the QuickCheck example for the first time: λ> quickCheck $ \xs -> reverse xs === xs +++ OK, passed 100 tests. I tried it multiple times. Somehow QuickCheck runs through 100 happy cases. :( How come? Other examples work better: λ> quickCheck $ -> sqrt(n^2) === n *** Failed! Falsifiable (after 7 tests and 4 shrinks): -1.0 1.0 /= -1.0 λ> quickCheck $ -> sqrt(n^2) === abs n +++ OK, passed 100 tests.
I am not the speaker, but the answer to your question is related to polymorphism. Your list xs has a polymorphic type [a], which quickCheck defaults to [()], that is a list of units (). Since there is only one value of type (), reverse xs == xs always succeeds. Specializing the type to [Int] fails: > quickCheck $ \xs -> (reverse xs :: [Int]) == xs *** Failed! Falsifiable (after 5 tests and 1 shrink): [0,1] I agree that it's confusing, though.
Oh, I didn't know I could use QuickCheck to help me come up with missing unit tests. So nice!
Thanks for the video! I'm trying the QuickCheck example for the first time:
λ> quickCheck $ \xs -> reverse xs === xs
+++ OK, passed 100 tests.
I tried it multiple times. Somehow QuickCheck runs through 100 happy cases. :( How come?
Other examples work better:
λ> quickCheck $
-> sqrt(n^2) === n
*** Failed! Falsifiable (after 7 tests and 4 shrinks):
-1.0
1.0 /= -1.0
λ> quickCheck $
-> sqrt(n^2) === abs n
+++ OK, passed 100 tests.
I am not the speaker, but the answer to your question is related to polymorphism. Your list xs has a polymorphic type [a], which quickCheck defaults to [()], that is a list of units (). Since there is only one value of type (), reverse xs == xs always succeeds.
Specializing the type to [Int] fails:
> quickCheck $ \xs -> (reverse xs :: [Int]) == xs
*** Failed! Falsifiable (after 5 tests and 1 shrink):
[0,1]
I agree that it's confusing, though.
Check what the instance being used is for the list elements is!
Wonderful talk! I reproduced the examples and verified they behave as expected: github.com/jmitchell/developers-intuition.hs