Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在学习 ML,有人可以解释一下详尽的模式是什么意思吗?
如果模式匹配不会失败,则它是详尽的。即所有可能发生的情况都被一个模式覆盖。
例如,以下模式匹配并不详尽,因为它没有涵盖列表为空的情况:
fun sum (x::xs) = x + sum xs
以下是详尽的,因为这两种情况都包括在内:
fun sum (x::xs) = x + sum xs | sum [] = 0
通常,当且仅当存在默认情况或所有构造函数都存在情况并且每个子模式的匹配是详尽的时,代数数据类型上的模式匹配才是详尽的。