2014-11-03 95 views
1

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

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) -> .... 

回答

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

值得一提的是,在匹配模式能分到这是与许多领域的记录是有用的,像记录的不是所有的字段'有些({B = b}) - > //在这里使用b ... – Petr 2014-11-04 00:02:40