是否可以对递归类型使用显式成员约束?
以下工作正常(非递归):
type Wrapper< ^a when ^a : (static member Baz: string) > = Wrapper of ^a
type Foo =
{ Str: string }
static member Baz = ""
type Bar =
{ Foo: Wrapper<Foo> }
static member Baz = ""
问题是我还需要Foo
类型Wrapper<Bar>
上的字段。但是,一旦我将type Bar
更改为and Bar
以启用此功能(或使整个模块递归),我会收到以下错误:
type Wrapper< ^a when ^a : (static member Baz: string) > = Wrapper of ^a
type Foo =
{ Str: string }
static member Baz = ""
and Bar =
{ Foo: Wrapper<Foo> }
// ^^^^^^^^^^^^ The type 'Foo' does not support the operator 'get_Baz'
static member Baz = ""
是否可以对递归类型使用显式成员约束?