I have a generic class with the default constructor accepting an argument of the generic type. When creating a second, non-generic constructor, the F# compiler complains that This type parameter has been used in a way that constrains it to always be 'EmptyType', and I don't understand this error at all. Why does it constrains? What does the second constructor has to do with the generic property of the first?
This example shows the error (reproducible in F# playground). Notice that simply commenting the second constructor (line 9), solves the compilation issue:
type MyInterface = interface end
type EmptyType() = interface MyInterface
type RealType(v: int) =
member this.Value = v
interface MyInterface
type MyType<'T when 'T :> MyInterface>(element: 'T) =
new() = MyType(EmptyType())
member this.X = 0
[<EntryPoint>]
let main _ =
//let a = MyType() //empty constructor, 'T is EmptyType
let b = MyType(RealType(0)) //doesnt work because compiler says 'T is always EmptyType? what?
0