Electric Coffee
Electric Coffee

Reputation: 12104

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?

Upvotes: 4

Views: 501

Answers (1)

John Palmer
John Palmer

Reputation: 25516

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 = ()

Upvotes: 8

Related Questions