【问题标题】:sml suppress warnings for intentionally nonexhaustive pattern matchingsml 抑制故意非详尽模式匹配的警告
【发布时间】:2013-03-16 14:53:05
【问题描述】:

假设我有一个像这样的数据类型:

datatype location = Safe of string | Dangerous of string * int;

在这个假设的例子中,我想编写一个函数,它只会传递Safe str 而永远不会传递Dangerous(str, num)

fun send_kids (Safe address) = ...

有没有办法抑制警告?告诉 SML 我知道不详尽?

stdIn:1.6-1.29 Warning: match nonexhaustive
          Safe s => ...

【问题讨论】:

    标签: sml


    【解决方案1】:

    不直接。您可以通过详尽的失败案例来“告诉” SML:

    fun sendKinds (Safe address) = ...
      | sendKinds _ = raise Fail "sendKinds"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多