em7*_*m70 5 f# currying visual-studio-2010
在将一些代码迁移到VS2010 b1中包含的最新版本的F#时,我遇到了一个问题,我想知道是否有可用的解决方法 - 如果没有 - 为什么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
Run Code Online (Sandbox Code Playgroud)
此代码生成以下编译时错误:
错误FS0191:此方法的一个或多个重载具有curried参数.考虑重新设计这些成员以采用tupled形式的参数
请注意,这曾经在F#1.9.6.2(9月CTP)上完美运行
更改的原因在于详细的发行说明:
咖喱方法的优化
一个咖喱成员看起来像这样:
type C()=
Run Code Online (Sandbox Code Playgroud)static member Sum a b = a + b在以前的F#实现中,curried成员的编译效率低于非curried成员.现在已经改变了.但是,现在对curried成员的定义有一些小的限制:
- 咖喱成员可能不会超载
- 可能需要调整一些咖喱成员的定义,以便为定义添加正确数量的参数
由于您的重载只能在第一个参数上解决,因此您应该能够通过将curried版本更改为:
[<OverloadID("CurriedAbc")>]
member public x.Abc (p:(oneType * anotherType) seq)
= fun otherParm -> method impl...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
914 次 |
| 最近记录: |