F#实例语法 [英] F# instance syntax
本文介绍了F#实例语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您在F#中用于成员声明的指示器是什么?我更喜欢
member a.MethodName
这是很多字母,否则使用 x .
解决方案
我几乎总是使用x
作为 this 实例的名称.除了它比其他选项短之外,没有任何逻辑可言.
我看到的选项是:
member x.Foo // Simply use (short) 'x' everywhere
member ls.Foo // Based on type name as Benjol explains
member this.Foo // Probably comfortable for C# developers
member self.Foo // I'm not quite sure where this comes from!
member __.Foo // Double underscore to resemble 'ignore pattern'
// (patterns are not allowed here, but '__' is identifier)
基于类型名称的选项在某种意义上是有意义的(当在类型内部嵌套对象表达式时很好),但是我认为为每个类型名称找到合理的2/3缩写可能非常困难. /p>
What indicator do you use for member declaration in F#? I prefer
member a.MethodName
this is to many letters and x is used otherwise.
解决方案
I do almost always use x
as the name of this instance. There is no logic behind that, aside from the fact that it is shorter than other options.
The options that I've seen are:
member x.Foo // Simply use (short) 'x' everywhere
member ls.Foo // Based on type name as Benjol explains
member this.Foo // Probably comfortable for C# developers
member self.Foo // I'm not quite sure where this comes from!
member __.Foo // Double underscore to resemble 'ignore pattern'
// (patterns are not allowed here, but '__' is identifier)
The option based on the type name makes some sense (and is good when you're nesting object expressions inside a type), but I think it could be quite difficult to find reasonable two/three abbreviation for every type name.
这篇关于F#实例语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文