首页 文章

F#:curried overload / tupled overload问题

提问于
浏览
5

在将一些代码迁移到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

此代码生成以下编译时错误:

错误FS0191:此方法的一个或多个重载具有curried参数 . 考虑重新设计这些成员以采用tupled形式的参数

请注意,这曾经在F#1.9.6.2(9月CTP)上完美运行

1 回答

  • 7

    更改的原因在detailed release notes

    Curried方法的优化curried成员如下所示:type C()= static member Sum a b = a b
    在以前的F#实现中,curried成员的编译效率低于非curried成员 . 现在已经改变了 . 但是,现在对curried成员的定义有一些小的限制:curried成员可能不会超载一些curried成员的定义可能需要调整,以便在定义中添加正确数量的参数

    由于您的重载只能在第一个参数上解决,因此您应该能够通过将curried版本更改为:

    [<OverloadID("CurriedAbc")>]
        member public x.Abc (p:(oneType * anotherType) seq)
           = fun otherParm -> method impl...
    

相关问题