假设我定义了一个 F# 可区分联合,如下所示:
type Union<'T> = | A of 'T | B | C
例如,如果我有一个B
where 'T
is int
,我将如何将它转换为另一个B
where 'T
is a string
?我有一个与此类似的联合,但有更多情况,目前我的模式匹配如下:
let convert u =
match u with
| A(x) -> // some fancy logic here
| B -> B
| C -> C