Consider the following:
type T () =
member x.y = 4
let a =
let fn () (k: T) = ()
fn ()
let b =
let fn () (k: System.IO.Directory) = ()
fn ()
a fails while b is ok. The error message is:
The value ‘a’ has been inferred to have generic type val a : (‘_a -> unit) when ‘_a :> T Either make the arguments to ‘a’ explicit or, if you do not intend for it to be generic, add a type annotation
Why and how to fix that?
The error message itself tells you exactly what you need to do – add a type annotation:
The reason that you see the error in the first place is that the compiler tries to generalize the definition of
a(see this part of the spec), which results in the odd signature that you see in the error message.The reason that you don’t need to do this for
bis thatSystem.IO.Directoryis sealed, so there is no need to generalize.