Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type of the Item property in F#

Consider the interface:

type IVector = 
    abstract Item : int -> float

Now, let us define the class:

type DenseVector(size : int) = 
    let mutable data = Array.zeroCreate size

    interface IVector with 
        member this.Item with get n = data.[n]

What about supply a method to mutate the n-th entry of the dense vector? Then, it would be nice to modify the above code as:

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

However, I get the following error because of the signature of the abstract method Item in the IVector interface:

No abstract property was found that corresponds to this override.

So, what should be the signature of Item in IVector?

like image 253
Allan Avatar asked Sep 10 '10 02:09

Allan


1 Answers

type IVector =  
    abstract Item : int -> float with get, set
like image 164
Brian Avatar answered Sep 28 '22 14:09

Brian