namespace Test
type Foo() =
member this.HelloFoo = "Foo"
member this.HelloFooBar =
let b = new Bar() // Why is Bar not visible here?
this.HelloFoo + b.HelloBar
type Bar() =
member this.HelloBar = "Bar"
为什么Bar在Foo中不可见?
答案 0 :(得分:7)
F#声明从上到下进行处理,因此Bar
尚未在Foo
中引用它时定义Bar
。您需要将Foo
的定义移到and
之上。
如果您的类型是相互依赖的,那么您可以使用type Foo =
...
and Bar =
...
来声明它们,例如
{{1}}