In the following code, UnitClass1.F seems to override BaseClass1<unit>.F , but not really. Can anyone explain the reason?
// Method case. type [<AbstractClass>] BaseClass1<'x>() = abstract member F: unit -> 'x type UnitClass1() = inherit BaseClass1<unit>() // ERROR: F: unit -> unit doesn't have the correct type to override the corresponding abstract method. override this.F() = () // ERROR: Wrong number of parameters. //override this.F(()) = () // ERROR: UnitClass1 doesn't have an implementation for abstract member F: unit -> 'x //member this.F() = ()
This problem also occurs in properties.
// Property case. type [<AbstractClass>] BaseClass2<'x>() = abstract member P: 'x type UnitClass2() = inherit BaseClass2<unit>() // The same error as the above. member this.P = ()
However, if I move the general parameter to the parameter side, then this code compiles.
type [<AbstractClass>] BaseClass3<'x>() = abstract member F: 'x -> unit type UnitClass3() = inherit BaseClass3<unit>() // OK override this.F(()) = ()
For a reason, they compile if 'x not unit .
type [<AbstractClass>] BaseClass4<'x>() = abstract member P: 'x type UnitClass4() = inherit BaseClass4<int>()
ENVIRONMENT: Windows 10, F # 4.0, Visual Studio 2015 Community
vain0 source share