gpt4 book ai didi

visual-studio-2010 - F#: curry 重载/成倍重载问题

转载 作者:行者123 更新时间:2023-12-04 18:17:20 25 4
gpt4 key购买 nike

在将某些代码迁移到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
此代码产生以下编译时错误:
error FS0191: One or more of the overloads of this method has curried arguments. Consider redesigning these members to take arguments in tupled form

请注意,这在F#1.9.6.2(9月CTP)上可以正常工作

最佳答案

更改的原因在detailed release notes中:

Optimizations for Curried Methods

A curried member looks like this:

type C() =

static member Sum a b = a + b    

In previous implementations of F# curried members were compiled less efficiently than non-curried members. This has now been changed. However, there are now some small restrictions on the definition of curried members:

  • curried members may not be overloaded
  • some definitions of curried members may need to be adjusted to add the correct number of parameters to the definition


由于只能在第一个参数上解决重载,因此您应该能够通过将 curry 版本更改为以下方式来解决它:
    [<OverloadID("CurriedAbc")>]
member public x.Abc (p:(oneType * anotherType) seq)
= fun otherParm -> method impl...

关于visual-studio-2010 - F#: curry 重载/成倍重载问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/920584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com