给定一个受成员约束约束的值,我可以将成员作为一等函数访问吗?
是否可以将受约束的成员作为一等函数(给定一个对象)进行访问?如果是这样,正确的语法是什么?
// Example: property getter as a first-class function
type Test() =
member x.Value = "42"
let t = Test()
let getter = t.get_Value // works as expected
// now generically:
let inline getGetter< ^a when ^a : (member get_Value : unit -> string)> item =
// call getter
let value = (^a : (member get_Value : unit -> string) item)
// try to get getter as first-class function
let getter = item.get_Value // doesn't compile: "Lookup on object of indeterminate type..."
()
Is it possible to access a constrained member as a first-class function (given an object)? If so, what is the correct syntax to use?
// Example: property getter as a first-class function
type Test() =
member x.Value = "42"
let t = Test()
let getter = t.get_Value // works as expected
// now generically:
let inline getGetter< ^a when ^a : (member get_Value : unit -> string)> item =
// call getter
let value = (^a : (member get_Value : unit -> string) item)
// try to get getter as first-class function
let getter = item.get_Value // doesn't compile: "Lookup on object of indeterminate type..."
()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这就是您正在寻找的:
I think this is what you are looking for: