In the last line of the following code snippet, I get two warnings: This construct causes code to be less generic than indicated by the type annotations. The type variable 'c has been constrained to be type ''a'. and This construct causes code to be less generic than indicated by the type annotations. The type variable 'b has been constrained to be type ''a * 'a'.
type SomeBaseClass<'a> () =
class end
type SomeClass<'a when 'a:equality> (getValue:unit->'a, ?arg2:SomeBaseClass<'b>) =
inherit SomeBaseClass<'a*'a>()
member this.Value with get () = getValue ()
member this.Transform (transformation:'a->'c) =
let func ():'c = transformation this.Value
SomeClass<'c> (func, this) // warnings are attached to this line
This, on the other hand, compiles without issue:
type SomeOtherClass<'a when 'a:equality> (getValue:unit->'a) =
inherit SomeBaseClass<'a*'a>()
member this.Value with get () = getValue ()
member this.Transform (transformation:'a->'c) =
let func ():'c = transformation this.Value
SomeOtherClass<'c> func
I don't see anything preventing transformation from returning a different type than it gets passed. I also don't see why that second warning is even a warning because it's obviously already my intention for the 'b type parameter of the new instance to be 'a*'a.
What am I doing wrong here?