【发布时间】:2015-07-22 21:48:35
【问题描述】:
在 ghci 中这段代码:
let max [] = error "maximum of empty list"
let max [x] = x
let max (x:xs)
| x > maxTail = x
| otherwise = maxTail
where maxTail = max xs
导致错误:*** Exception: <interactive>:26:5-106: Non-exhaustive patterns in function max
这里的不可穷尽的模式是什么?满足零元素、单元素和多元素列表吗?
更新 2:
更新 3:
在 Debian (Raspberry Pi) 上按预期工作:
【问题讨论】:
-
您的屏幕截图中没有
:{和:}。 -
现在看起来是正确的。我有点困惑为什么它没有插入“前奏|”虽然在每一行之前。也许 WinGHCi 和多行模式和/或粘贴之间存在一些奇怪的交互。
-
我使用 WinGHCi,但我一直无法将多行粘贴到其中。