这是我的示例代码。我一直无法弄清楚如何使我的State
sum-type 递归,同时仍然允许它在其他地方像 sum-type 一样使用。我的StateMachine
类型也是如此。
let State =
< Task : { Comment : Text, Resource : Text, End : Bool }
| Map : { Comment : Text, Iterator : StateMachine }
| Parallel : { Comment : Text, Branch : List State }
>
let StateMachine
: Type
= { Comment : Optional Text
, StartAt : Text
, States : List { mapKey : Text, mapValue : State }
}
let test
: StateMachine
= { Comment = Some "A simple minimal example"
, StartAt = "Hello World"
, States =
[ { mapKey = "Hello World"
, mapValue =
State.Task { Type = "Task", Resource = "Test", End = True }
}
]
}
in test
是否有一种合理的方法可以做到这一点,不会增加代码大小并使最终用户导入和使用的类型符合人体工程学?如果从示例中看不出来,我正在尝试对状态机进行模式化。
我尝试了以下方法,但我收到“不是记录或联合”错误State.Task
:
let State
: Type
= ∀(_State : Type)
→ ∀(Task : { Type : Text, Resource : Text, End : Bool })
→ ∀(Map : { Type : Text, Iterator : _State })
→ _Stat