If T, where is the entry instead of the class, this will work. But for some reason you have to specify it for the compiler, if T is a class,
type T () = member xy = 4 let a<'U when 'U :> T> = let fn () (k: 'U) = () fn () let test0 = a<T> (T()) // You can be explicit about T, let test1 = a (T()) // but you don't have to be.
edit: So, I played around a bit with this, and, oddly enough, the compiler seems to be satisfied only with any type of constraint:
type T () = member xy = 4 type S () = member xz = 4.5 let a<'U when 'U :> S> = let fn () (k: T) = () fn () let test = a (T()) // Is OK let test = a<T> (T()) // Error: The type 'T' is not compatible with the type 'S'
Type S has nothing to do with the code above, but the compiler with pleasure just has a restriction of any type.
source share