我想对 Web 应用程序的路由进行建模,使其满足以下要求:
作为使用的示例:
type root =
| Fruit of fruit
| Veggie of veggie
and fruit =
| Apple of apple
| Banana of banana
and veggie =
| Carrot of carrot
and apple = { diameter: int; cultivar: string; }
and banana = { length: int }
and carrot = { length: int; color: [`Orange | `Purple] }
Run Code Online (Sandbox Code Playgroud)
有了这个,我们可以轻松创建和执行完整的定义:
let complete = Fruit (Apple { diameter = 8; cultivar = "Golden Delicious" })
Run Code Online (Sandbox Code Playgroud)
但无法创建不完整的定义 …