如何在 F# 列表上定义扩展方法?
像这样天真的尝试会导致错误:
type list with
member this.abc() = 100
最佳答案
正确的语法是:
type List<'a> with
member this.abc() = 100
您可以使用限定名 Microsoft.FSharp.Collections.List<'a>
也一样,但类型缩写 list<'a>
无法使用。
也就是说,使用模块函数更加地道。您应该制作一个模块功能,以便通过管道 (|>)
轻松与其他功能组合。运营商:
module List =
let abc (xs: _ list) = 100
关于f# - 列表中的扩展方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15090990/