【发布时间】:2018-06-09 17:54:42
【问题描述】:
如何让编译器忽略一些向下转换的模式匹配警告 (FS0025) 但必须在同一文件中捕获其他 FS0025 警告?
例如,第一个模式匹配 (Student studentName) = john 永远不会抛出错误,所以我希望编译器删除不必要的警告。
type Job = Student of string | Teacher of string
let john = Student "John"
(* FS0025: Incomplete pattern matches on this expression. For example,
the value 'Teacher _' may indicate a case not covered by the pattern(s). *)
let (Student studentName) = john
let (Teacher teacherName) = john // runtime error
我试过了:
#nowarn "25"
let (Student studentName) = john
#warn "25"
let (Teacher teacherName) = john
但它没有显示let (Teacher teacherName) = john 的任何警告错误。
【问题讨论】:
标签: .net f# functional-programming pattern-matching