假设我有一个类似的数据类型:
datatype location = Safe of string | Dangerous of string * int;
在这个假设的例子中,我想编写一个只传递Safe str
而不传递Dangerous(str, num)
的函数:
fun send_kids (Safe address) = ...
有没有办法压制警告?告诉SML我知道 tis nonexhaustive?
stdIn:1.6-1.29 Warning: match nonexhaustive
Safe s => ...
答案 0 :(得分:2)
不直接。你通过在失败案例中详尽无遗来“告诉”SML:
fun sendKinds (Safe address) = ...
| sendKinds _ = raise Fail "sendKinds"