我试图了解受歧视的工会和记录类型;特别是如何组合它们以获得最大的可读性。这是一个例子 - 假设一个运动队可以有积分(联赛积分和净胜球),或者它可以被停赛,在这种情况下它没有积分或净胜球。以下是我试图表达的方式:
type Points = { LeaguePoints : int; GoalDifference : int }
type TeamState =
| CurrentPoints of Points
| Suspended
type Team = { Name : string; State : TeamState }
let points = { LeaguePoints = 20; GoalDifference = 3 }
let portsmouth = { Name = "Portsmouth"; State = points }
问题出现在最后一行的末尾,我说“State = points”。我得到“表达式应该有 TeamState 类型,但这里有 Points 类型”。我该如何解决?