How to call methods from the constructor in F #

I know this question , but it seems the crawler is satisfied with the answer to another question (how to overload the constructor)

I have a class that acts as an extended memoizer around a mutable class, so that I can treat it as immutable from the 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 

I cannot figure out how to call the Init method on a "tool". What am I missing?

+5
constructor f #
source share
2 answers

IIRC, the do keyword may 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 ...

+8
source share

You need to do:

 type Foo(args) = let x = new Whatever() do x.Bar() member .... 
+5
source share

All Articles