以下两个函数在输入空字符串时有不同的行为:
问题:为什么“otherwise”不能捕获空字符串?
guardMatch l@(x:xs)
| x == '-' = "negative " ++ xs
| otherwise = l
patternMatch ('-':xs) = "negative " ++ xs
patternMatch l = l
以下是我的输出:
*Main> guardMatch ""
"*** Exception: matching.hs:(1,1)-(3,20): Non-exhaustive patterns in function guardMatch
*Main> patternMatch ""
""
问题:为什么“otherwise”不能捕获空字符串?