相关疑难解决方法(0)

内联时扩展方法出错

我想扩展一些系统类型,然后通过内联使用它们

type System.String with  
    member this.foo n = this + "!" + n 

type System.Boolean with  
    member this.foo n = sprintf "%A!%A" this n 
Run Code Online (Sandbox Code Playgroud)

现在我调用这些扩展方法

let x = "foo".foo "bar"
let y = true.foo "bar"
Run Code Online (Sandbox Code Playgroud)

这给了我这个

- val x : System.String = "foobar"
- val y : string = "true!"bar""
Run Code Online (Sandbox Code Playgroud)

所有罚款和花花公子 - 但现在我想将调用包装.foo成内联函数

let inline foo n v = (^T : (member foo : ^N  -> ^S) v, n)
let z = foo "bar" "baz" 
Run Code Online (Sandbox Code Playgroud)

只是现在我收到编译错误告诉我

> The …
Run Code Online (Sandbox Code Playgroud)

f#

4
推荐指数
1
解决办法
110
查看次数

标签 统计

f# ×1