Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# How do I access a member from a function

I'm pretty new to F# so I'm not quite sure what I'm doing wrong here here's what I'm trying to do:

type MyClass() =
    let someVar = this.MyMember()

    member this.MyMember() :unit = 
        // insert some code here

I can't do that because Visual Studio tells me that "this" isn't defined so what should I do? am I missing some obvious feature of F# or something?

I tried making all my members functions instead... but then I'd have to re-order all the functions so they become visible and then it still wouldn't work

so what do?

like image 989
Electric Coffee Avatar asked Feb 16 '23 17:02

Electric Coffee


1 Answers

You need to insert a self-identifier. This is not done by default for some performance reasons.

The following works:

type MyClass() as this =
    let someVar = this.MyMember()

    member this.MyMember() :unit = ()
like image 77
John Palmer Avatar answered Mar 04 '23 10:03

John Palmer