我是F#的菜鸟,目前在F#3.0上阅读专家.它是我正在学习的第一个编译语言(我只知道在R中编程)
在第6章,第117页,我们介绍了没有太多仪式静态let和静态成员.我真的不明白它是什么
type Vector2D(dx : float, dy : float) =
static let zero = Vector2D(0.0, 0.0)
static let onex = Vector2D(1.0, 0.0)
static let oney = Vector2D(0.0, 1.0)
/// Get the zero vector
static member Zero = zero
/// Get a constant vector along the X axis of length one
static member OneX = onex
/// Get a constant vector along the Y axis of length one
static member OneY = oney
Run Code Online (Sandbox Code Playgroud)
没有任何例子可以在书中继续进行.
我在F#interactive中键入它.从那里,我如何构造一个值为零(或onex ...)的变量x?
我正在尝试以下方法.什么都行不通
let x = Zero;;
let y = Vector2D(2.0,2.0);; /// ok
y.Zero;;
stdin(237,1): error FS0809: Property 'Zero' is static
Run Code Online (Sandbox Code Playgroud)
在http://fsharpforfunandprofit.com/posts/classes/中 有这个例子,
type StaticExample() =
member this.InstanceValue = 1
static member StaticValue = 2 // no "this"
// test
let instance = new StaticExample()
printf "%i" instance.InstanceValue
printf "%i" StaticExample.StaticValue
Run Code Online (Sandbox Code Playgroud)
所以我本来期望y.Zero;;产生一些东西?...
谢谢.抱歉,这个问题非常基础.如果有人能解释我的意思......