我知道this question,但是提问者似乎满足于回答另一个问题(如何重载构造函数)
我有一个类作为围绕可变类的高级memoizer,因此我可以将它视为来自外部的不可变:
type Wrapper(args) =
let tool = new MutableTool()
tool.Init(args) //<--"Unexpected identifier in definition"
let lookupTable = //create lookup using tool here
member this.Lookup(s) = //callers use lookupTable here
我无法弄清楚如何在“工具”上调用Init方法。我错过了什么?
答案 0 :(得分:8)
IIRC,do
关键字可能适用于此处:
type Wrapper(args) =
let tool = new MutableTool()
do tool.Init(args)
let lookupTable = //create lookup using tool here
member this.Lookup(s) = //callers use lookupTable here
我不确定你对最后一行代码的含义是什么,所以当你写它时我就把它留下了...
答案 1 :(得分:5)
你需要“做”:
type Foo(args) =
let x = new Whatever()
do x.Bar()
member ....