【发布时间】:2011-09-28 22:48:06
【问题描述】:
以下两个函数在给定空字符串时表现不同:
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' close 不能捕获空字符串?
【问题讨论】:
标签: haskell pattern-matching guard-clause