如果我有多个值共用一个孩子(Apple
和MoreApples
都有型Apple
)可识别联合...比赛对儿童识别联合
type Apples =
| GrannySmith
| Gala
type Fruit =
| Apple of Apples
| MoreApples of Apples
| Banana
let speakFruit = function
| Apple GrannySmith
| MoreApples GrannySmith -> "granny smith"
| Apple Gala
| MoreApples Gala -> "gala"
| Banana -> "banana"
有没有一种方法,以匹配子联盟删除重复? - 像这样:
let speakFruit2 = function
| _ GrannySmith -> "granny smith"
| _ Gala -> "gala"
| Banana -> "banana"
你是完全控制你的类型还是他们的第三方?如果前者然后可能会做[像这样](https://ideone.com/Slqg4F)而不是? – ildjarn
没有办法做到这一点,而这实际上表明你的类型没有足够好地反映你的域名。 –