2013-12-23 42 views
1
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中不可見?名稱空間中類的可見性

回答

7

F#聲明從上到下進行處理,所以Bar尚未在Foo中引用的點處定義。您需要將Bar的定義移到Foo以上。

如果你的類型是相互依賴的,那麼你可以使用and來聲明它們。

type Foo = 
... 
and Bar = 
... 
相關問題