Can please someone explain this to me:
type IItem = interface end
type Item = {i:int} interface IItem
type Fail = static member foo (s:string) = fun (x:IItem) -> ""
let foo = fun (s:string) -> fun (x:IItem) -> ""
let works = {i=1} |> foo ""
let fails = {i=1} |> Fail.foo ""
Why does the currying with the static member function not work? I'm using Visual Studio 2012 with .net 4.5.2 if that matters.
This isn't really a difference between static members and functions - it's a bit more subtle. Here's another repro:
Note that the signatures of
T.A
andT.B
are different (this is actually covered in section 11.2.1.1 of the spec):This is a distinction that is usually unimportant, but basically it means that at a .NET representation level
A
is compiled to a method with two arguments (even though it looks curried in F#) whileB
is compiled to a method with a single argument which returns an F# function. This difference is ultimately what causes the behavior you're seeing.