2009-11-05 121 views
3
type IFooable = 
    abstract Foo : int -> int 

type IFooable2 = 
    abstract Foo : a : int -> int 

type MyClass() = 
    interface IFooable2 with 
     member this.Foo(b) = 7 

IFooable和IFooable2有什么区别?它们是否相同? 在我的例子中,它的目的是什么?何时使用它?这两种语法之间的区别

回答

4

IFooable2命名其参数; IFooable没有。

当系统反映参数名时,这很重要。例如,当您使用带有ServiceContractAttribute标记的接口类型的WCF时,默认情况下,WCF会使用接口中的参数名称来控制出现在线路上数据的XML投影中的名称。

这也适用于工具,例如,从C#引用此F#代码,声明每种类型的变量,并查看每种方法的智能感知工具提示。

我建议总是声明参数名称(更喜欢第二个版本)。