名称空间中类的可见性

Mai*_*ein 1 f#

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"
Run Code Online (Sandbox Code Playgroud)

为什么在Foo中看不到Bar?

Lee*_*Lee 7

F#声明从上到下进行处理,因此Bar尚未在引用它时定义Foo.您需要移动Bar上面的定义Foo.

如果您的类型是相互依赖的,那么您可以使用and它们来声明它们

type Foo =
...
and Bar =
...
Run Code Online (Sandbox Code Playgroud)