Generics 为什么F#中的接口实现没有编译?

Generics 为什么F#中的接口实现没有编译?,generics,interface,f#,equality,Generics,Interface,F#,Equality,我试图为F#中的特定类实现IEquatable。然而,在这种情况下,我得到了一个意外的错误 我有以下代码: type Foo private (name : string) = member this.Name = name member this.Equals (other : Foo) = this.Name = other.Name override this.Equals other = match other with | :? Foo as foo -> thi

我试图为F#中的特定类实现
IEquatable
。然而,在这种情况下,我得到了一个意外的错误

我有以下代码:

type Foo private (name : string) = 

member this.Name = name

member this.Equals (other : Foo) = this.Name = other.Name

override this.Equals other =
    match other with | :? Foo as foo -> this.Equals foo | _ -> false

override this.GetHashCode () = this.Name.GetHashCode ()

interface IEquatable<Foo> with
    this.Equals other = this.Equals other
键入Foo private(名称:string)=
成员:this.Name=Name
成员this.Equals(other:Foo)=this.Name=other.Name
覆盖这个,等于其他=
用|:?Foo as Foo->this.等于Foo | | |->false
重写this.GetHashCode()=this.Name.GetHashCode()
接口与
这个等于其他

这是不可编译的。我得到了以下错误:“意外的关键字”和“成员定义中的”。此外,我还得到了“可能不正确的缩进…”。。。“警告。我不确定问题出在哪里,因为在我看来,上面提到的接口通常是如何在F#中实现的。为什么上面没有编译?

好吧,我可以自己回答这个问题。我没有把成员放在实现的前面。交换

this.Equals other = this.Equals other


让一切都好起来。编译器在这个问题上概述了“with”关键字这一事实让我感到很不舒服。

在F#的更高版本中已经做了一些改进错误报告的工作。这似乎是一个很好的候选人。也许将此作为问题发布在:github.com/microsoft/visualfsharp/issues?
member this.Equals other = this.Equals other