【发布时间】:2015-07-27 11:46:05
【问题描述】:
我有一个这样的 DU:
type Food =
| Beer
| Bacon
| Apple
| Cherry
我想在 DU 中添加一个特征来标记食物是否是水果。我首先想到的是这样的:
type NonFruit = NonFruit
type Fruit = Fruit
type Food =
| Beer of NonFruit
| Bacon of NonFruit
| Apple of Fruit
| Cherry of Fruit
然后是这样的方法:
让fruitChecker (myFood:Food) = 将 myFood 与 | :?非水果->“否” | :?水果 -> “是”
但是编译器在骂我:
“食物”类型没有任何适当的子类型,无法使用 作为来源
我是不是错误地处理了这个问题?
谢谢
【问题讨论】:
标签: f#