2013-02-26 25 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