我正在尝试这个:
type TS1<'state, 'action> = {
actions : 'state -> #seq<'action>
move : 'state -> 'action -> 'state
state0 : 'state
}
Run Code Online (Sandbox Code Playgroud)
但类型检查器不会让我:
.../stdin(2,29):error FS0715: Anonymous type variables are not permitted in this declaration
Run Code Online (Sandbox Code Playgroud)
但是,如果我展开灵活类型的定义,我很好:
type TS2<'state, 'action, 'actions when 'actions :> seq<'action>> = {
actions : 'state -> 'actions
move : 'state -> 'action -> 'state
state0 : 'state
}
Run Code Online (Sandbox Code Playgroud)
我不满意必须添加'actions类型变量 - 它使得与确定性过渡系统的连接成为不太明显的数学对象.
通过在记录定义中允许灵活类型,我看不出会出现什么问题.它有点危险吗?还有其他方法我可以得到我想要的清晰度吗?
更新.我希望能够在利用已知实现的TS类型上编写函数; 即,我希望能够定义一个函数
let has_action a ts s = Set.contains a <| ts.actions …Run Code Online (Sandbox Code Playgroud)