The issue is F# and 'let rec' versus 'let'. 'member' functions are implicitly 'let rec'. I don't know enough of the language speci to point you at exactly why this happens, but the 'solution' is to be explicit (add generic type annotations) in the definition of Foo to force it to be generic.

By on 3/22/2009 2:45 PM ()

I believe that the answer is that the .NET type system makes inference a bit tricky due to subtleties like overloading, differences between functions taking no arguments and taking a single argument of type unit, etc. This means that type inference within types is a bit more limited than in modules. However, if you specify explicit types you can achieve the result that you want:

1
2
3
4
5
6
7
8
9
type SpecificSunshineType =
  static member Foo<'a,'b> (f:'a->'b->'a) (s:'a) (acc:'b list) : 'a =
    List.fold_left f s acc

  static member BarWithChar() =
    SpecificSunshineType.Foo (fun s acc -> s) 'a' ['a']
    
  static member BarWithInt() =
    SpecificSunshineType.Foo (fun s acc -> s) 1 [1]
By on 3/22/2009 2:01 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper