2009-05-28 60 views
5

將某些代碼遷移到VS2010 b1中包含的最新版本的F#時,遇到問題,我想知道是否有可用的解決方法 - 如果沒有 - 爲什麼F#編譯器的行爲被修改爲不支持該場景。F#:curried過載/元組過載問題


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)

回答

7

的原因完美的工作更改是在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

由於您的重載可以解決LY的第一個參數,你應該能夠通過改變咖喱版回合它的工作:

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

感謝您指出的標題問題,我寫了,我必須去解決,然後另外一個問題一個問題這一個來了,我只是忘了標題:( PS:我現在正在測試你的解決方案,看看它是否工作:D – em70 2009-05-28 13:20:00