【发布时间】:2018-11-07 18:40:53
【问题描述】:
考虑以下代码示例:
function
| [] -> "bla"
| ds -> let x::l = List.rev ds in "woot";;
编译/解释上述代码时会出现以下警告:
line 3, characters 14-18:
Warning 8: this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
[]
我想知道为什么会出现这个警告。很明显,由于顶级模式匹配, [] 不是有效选项。我希望 OCaml 的编译器/解释器能够通过将信息从顶级匹配传递到嵌套匹配来轻松推断出上述代码的详尽性。为什么不是这样?我错过了什么吗?
【问题讨论】: