Reputation: 2248
I created a simple function:
let myGenericFunc abc = printfn "%A" abc
Its type is:
'a -> unit
Then I want to make it a member of a class:
type MyClass() =
member x.Func = myGenericFunc
However, type of "Func" is now
obj -> unit
Moreover: If I make the parameter explicit, everything is ok again:
type MyClass() =
// Func : 'a -> unit
member x.Func y = myGenericFunc y
The question is: what happens ?!
Upvotes: 3
Views: 75
Reputation: 3697
Your first x.Func
is defining a property, not a method and because properties cannot be generic it has to use a concrete type for 'a
.
When you define x.Func y
you are creating a method and that can be generic.
Upvotes: 7