简体   繁体   English

F#如何从函数中访问成员

[英]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: 我对F#很陌生,所以我不太确定我在这里做错了什么我正在尝试做的事情:

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? 我不能这样做因为Visual Studio告诉我“这个”没有定义所以我该怎么办? am I missing some obvious feature of F# or something? 我错过了F#的一些明显特征还是什么?

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? 怎么办?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM