In F#, given the following class:
type Foo() =
member this.Bar<'t> (arg0:string) = ignore()
Why does the following compile:
let f = new Foo()
f.Bar<Int32> "string"
While the following won’t compile:
let f = new Foo()
"string" |> f.Bar<Int32> //The compiler returns the error: "Unexpected type application"
It looks that providing type parameters when treating method as a first class value isn’t supported. I checked the F# specification and here are some important bits:
If you specify type arguments and arguments, then the first case applies, but as you can see, the specification requires some actual arguments too. I’m not quite sure what is the motivation behind this, though.
Anyway, if you use the type parameter anywhere in the type signature of the member, then you can specify it using type annotations like this:
On the other hand, if you don’t use the type parameter anywhere in the signature, then I’m not quite sure why you need it in the first place. If you need it just for some runtime processing, then you may be able to take the runtime type representation as an argument: