在 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) 上按预期工作: