我有一段Haskell代码,可以恰当地利用单词。例如,它将需要" rObOT"并将其更改为" Robot"。一个函数是列表理解,另一个是递归。两者似乎完全相同(根据我通过它们的所有值)但尽管这个quickCheck声称它们不是等价的并且它们在1次测试后是可证伪的。
-- List-comprehension version
capitalise :: String -> String
capitalise xs = toUpper (head xs): [toLower x | x <- tail xs]
-- Recursive version
capitalFuncRec :: String -> String
capitalFuncRec [] = []
capitalFuncRec (x:xs) = toLower(x) : capitalFuncRec xs
capitaliseRec :: String -> String
capitaliseRec [] = []
capitaliseRec (x:xs) = (toUpper x) : capitalFuncRec xs
-- Mutual test ---
prop_capitalise :: String -> Bool
prop_capitalise xs = capitaliseRec xs == capitalise xs