如果我有多個值共用一個孩子(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
沒有辦法做到這一點,而這實際上表明你的類型沒有足夠好地反映你的域名。 –