这堂课在F#中看起来如何?

public class myClass : baseClass
{
    public myClass()
    {
        this.someVariable = "test";
        this.someFunction();
    }
}

到目前为止,我已经找到了(甚至正确吗?):

type myClass = class
        inherit baseClass
        new ()= 
            this.someFunction()
end

但是正在努力打电话给somefunction(),因为它说“这个”不是定义的

有帮助吗?

解决方案

这是翻译您的代码的一种方法:

type baseClass() =
    member this.someFunction() = printf "hello world\n"

type myClass() as this =
    inherit baseClass()
    let mutable someVariable = "test"
    do this.someFunction()
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top