在一个匹配模式中匹配并绑定记录类型的字段?

时间:2014-11-03 23:23:30

标签: f#

是否可以在匹配模式语句中匹配和绑定记录类型的字段?

type R = { A:int; B:string }
type R' = R option

let record: R' = .....
match record with
| Some(r) ->
     let a, b = r.A, r.B // Can this row be merged to the match pattern like the tuple example below?
     ....
| None -> ....

预期类似于以下内容的元组

match record with 
| Some(a, b) -> ....

1 个答案:

答案 0 :(得分:4)

match record with
| Some({A = a; B = b }) -> ...