F#:柯里化重载/元组重载问题
在将一些代码迁移到最新版本的 F#(包含在 VS2010 b1 中)时,我遇到了一个问题,我想知道是否有可用的解决方法,如果没有,为什么 F# 编译器的行为不修改为支持场景。
type Foo(a) =
[<OverloadID("CurriedAbc")>]
member public x.Abc (p:(oneType * anotherType) seq) otherParm = method impl...
//this overload exists for better compatibility with other languages
[<OverloadID("TupledAbc")>]
member public x.Abc (p:Dictionary<oneType, anotherType>, otherParm) =
x.Abc(p |> Seq.map(fun kvp -> (kvp.Key, kvp.Value))) otherParm
此代码会产生以下编译时错误:
错误 FS0191:此方法的一个或多个重载具有柯里化参数。 考虑重新设计这些成员以采用元组形式的参数
请注意,这曾经在 F# 1.9.6.2(9 月 CTP)上完美运行
While migrating some code to the latest version of F#, included in VS2010 b1, I've encountered an issue and I'd like to know if there's a workaround available and - if not - why was the behavior of the F# compiler modified not to support the scenario.
type Foo(a) =
[<OverloadID("CurriedAbc")>]
member public x.Abc (p:(oneType * anotherType) seq) otherParm = method impl...
//this overload exists for better compatibility with other languages
[<OverloadID("TupledAbc")>]
member public x.Abc (p:Dictionary<oneType, anotherType>, otherParm) =
x.Abc(p |> Seq.map(fun kvp -> (kvp.Key, kvp.Value))) otherParm
This code produces the following compile-time error:
error FS0191: One or more of the overloads of this method has curried arguments. Consider redesigning these members to take arguments in tupled form
Please mind that this used to work flawlessly on F# 1.9.6.2 (Sept. CTP)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改的原因位于 详细发行说明:
由于只能在第一个参数上解析重载,因此您应该能够通过将柯里化版本更改为:
The reason for the change is in the detailed release notes:
Since your overloading can be resolved only on the first parameter, you should be able to work round it by changing the curried version to: