All*_*lan 5 syntax f# functional-programming interface
考虑界面:
type IVector =
abstract Item : int -> float
Run Code Online (Sandbox Code Playgroud)
现在,让我们定义类:
type DenseVector(size : int) =
let mutable data = Array.zeroCreate size
interface IVector with
member this.Item with get n = data.[n]
Run Code Online (Sandbox Code Playgroud)
如何提供一种方法来改变密集向量的第n个条目?然后,将上面的代码修改为:
type DenseVector(size : int) =
let mutable data = Array.zeroCreate size
interface IVector with
member this.Item with get n = data.[n]
and set n value = data.[n] <- value
Run Code Online (Sandbox Code Playgroud)
不过,我得到,因为抽象方法的签名下面的错误Item的IVector界面:
未找到与此覆盖对应的抽象属性.
那么,究竟应该是签名Item的IVector?