Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 456
user3685285 Avatar asked Mar 23 '15 14:03

user3685285


Video Answer


1 Answers

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

like image 186
Petr Avatar answered Sep 26 '22 03:09

Petr