2013-02-26 27 views

回答

5

正确的语法是:

type List<'a> with 
    member this.abc() = 100 

可以使用合格的名称Microsoft.FSharp.Collections.List<'a>为好,但类型缩写list<'a>不能使用。

也就是说,使用模块函数更具惯用性。您应该使模块的功能,通过管道(|>)运营商:

module List = 
    let abc (xs: _ list) = 100 
+0

感谢垫。还有关于惯用代码的信息。 – dharmatech 2013-02-27 02:55:52

2
type Microsoft.FSharp.Collections.List<'T> with 
    member x.IsNotEmpty() = not (List.isEmpty x) 

let xs = [1] 
xs.IsNotEmpty