时,我想延长一些系统类型和以后通过内联使用它们错误的扩展方法内联
type System.String with
member this.foo n = this + "!" + n
type System.Boolean with
member this.foo n = sprintf "%A!%A" this n
现在我把这些扩展方法
let x = "foo".foo "bar"
let y = true.foo "bar"
这给了我这个
- val x : System.String = "foobar"
- val y : string = "true!"bar""
所有罚款和花花公子 - 但现在我想调用.foo
包装成一个内联˚F结
let inline foo n v = (^T : (member foo : ^N -> ^S) v, n)
let z = foo "bar" "baz"
只有现在我得到一个编译错误告诉我,
> The type 'string' does not support the operator 'foo':
以及...它!
有人能解释一下怎么回事?