【发布时间】:2020-01-24 09:52:41
【问题描述】:
我希望某物(人、物体等)具有能力(跳跃、奔跑等)。我希望有些东西只有特定的能力。这些是我目前的类型:
type Ability =
| Jump
| Stay
| Run
| Walk
type Person = {
abilities : Ability Set // OK, since a person should be able to do all of the above
}
type InanimateObject = {
abilities : Ability Set // Not OK, it should only be able to "Stay"
}
type ThingWithAbilities =
| Person of Person
| InanimateObject of InanimateObject
我希望我的 API 的调用者能够请求具有特定能力的 ThingWithAbilities。示例:给我ThingWithAbilities 的所有具有“跳跃”能力的对象。我怎样才能以一种好的方式对此进行建模?我想让在代码中创建具有“跳转”能力的InanimateObject 成为不可能。
【问题讨论】:
标签: f# data-modeling