I'm trying to use QuickCheck following another answer. I test like this:
{-# LANGUAGE TemplateHaskell #-}
import Test.QuickCheck
import Test.QuickCheck.All
last' :: [a] -> a
last' [x] = x
last' (_:xs) = last' xs
prop_test x = last' x == last x
check = do
putStrLn "quickCheck"
quickCheck (prop_test :: [Char]-> Bool)
check2 = do
putStrLn "quickCheckAll"
$quickCheckAll
Then I load it in winGHCI and call check
and check2
. I get
quickCheck
*** Failed! (after 1 test):
Exception:
list.hs:(7,1)-(8,23): Non-exhaustive patterns in function last'
""
which I think it's reasonable. However, I get this from check2
quickCheckAll
True
I'm confused because no matter how I change the last'
function, even wrong, quickCheckAll
always return True.
What's wrong with my code? How can I fix this?
quickCheckAll
). Very mysterious. – Seraphic