我正在尝试为绑定到F# 中特定泛型类型参数的泛型类型创建各种扩展方法,但该语言似乎不允许我:
我想做的是如下所示:
type IEnumerable<int> with
member this.foo =
this.ToString()
然而它给了我编译器错误(在int
关键字下划线):
类型名称中有意外的标识符。预期的中缀运算符、引号符号或其他标记。
以下确实有效,尽管它没有int
像我想要的那样专门将泛型类型参数绑定到:
type IEnumerable<'a> with
member this.foo =
this.ToString()
有什么方法可以在 F# 中实现这一目标 - 我可能只是使用了错误的语法吗?如果没有,如果有人可以提出解决方法,我将不胜感激,也许在某处使用类型约束。