How to invoke methods from constructor in F#

前端 未结 2 985
耶瑟儿~
耶瑟儿~ 2021-01-19 01:24

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)

I have a class which kind

相关标签:
2条回答
  • 2021-01-19 01:46

    IIRC, the do keyword might work here:

    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...

    0 讨论(0)
  • You need "do":

    type Foo(args) = 
      let x = new Whatever()
      do x.Bar()
    
      member ....
    
    0 讨论(0)
提交回复
热议问题