user3685285
user3685285

Reputation: 6626

F# calling member functions in constructor

I am writing an F# type, and I'm having trouble figuring out how to reference a member function from the constructor upon initialization. I think I'm supposed to use a do binding, but then the do binding can't understand the member functions. Is there no way around this?

Upvotes: 11

Views: 1420

Answers (1)

Petr
Petr

Reputation: 4280

You can do it this way:

type MyClass() as this =   // Note as this

    do this.SayHello()

    member this.SayHello() = 
        do printfn "Hello from constructor!"

But generally it is not a good practice

Upvotes: 16

Related Questions