如何从构造函数中调用方法F# [英] How to invoke methods from constructor in F#
本文介绍了如何从构造函数中调用方法F#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这个问题,但asker似乎内容与另一个答案的答案问题(如何重载构造函数)
I'm aware of this question, but the asker seems to have been content with an answer to another question (how to overload the constructor)
我有一个类作为一个可变类的高级memoizer,所以我可以把它看作是不可变的:
I have a class which kind of acts as an advanced memoizer around a mutable class, so that I can treat it as immutable from outside:
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方法。我缺少什么?
I can't work out how to invoke the Init method on "tool". What am I missing?
推荐答案
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
我不知道你最后一行代码是什么意思,所以我把它留在你写的...
I'm not sure what you meant with the last line of code, so I left it as you wrote it...
这篇关于如何从构造函数中调用方法F#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文