所以我一直在研究F#上的接口。我找到了這兩篇文章。 MSDN和F# for fun and profit但不幸的是,他們只是皮膚深。F#如何在單獨的模塊中使用接口
修訂
這裏是我與我的接口模塊
//open statements omitted for brevity
module DrawingInterfaces =
///gets a string representation of the SVG code representation of the object
type IRepresentable_SVG =
abstract member getSVGRepresenation : unit -> string
//other interfaces omitted for brevity
現在相同的命名空間和物理文件夾也中我有這樣的:
type lineSet (x1off,x2off,y1off,y2off,x1,x2,y1,y2,rot,rotOff,count) =
//tons of member vals omitted for brevity
member val x1Start = x1 with get, set
interface DrawingInterfaces.IRepresentable_SVG with
member __.getSVGRepresenation() =
let mutable svg = ""
let mutable currentx1 = x1Start
svg
這曾經給我2錯誤,在我使用__之前。爲會員提供符號。第一個錯誤是在接口線上。還有一條是成員線。 錯誤分別爲:
The type 'IRepresentable_SVG' is not defined
This instance member needs a parameter to represent the object being invoked.
我能夠通過更改文件順序來修復第一個錯誤。感謝John Palmer。 第二個幾乎是固定的。/
使用__後。符號我能夠擺脫第二個錯誤。但是,當我嘗試在接口實現中使用類型成員時,現在會彈出一個新錯誤。
let mutable currentx1 = x1Start
x1Start顯示爲未定義。我需要能夠在我的實現中使用存儲在其他成員中的值。
F#對文件編譯順序很敏感。定義文件是否在Visual Studio中的用法文件之上? –
更改編譯順序解決了第一個問題。 –