在下面的代码中,UnitClass1.F似乎覆盖BaseClass1<unit>.F,但实际上没有.有人能说出原因吗?
// 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() = ()
Run Code Online (Sandbox Code Playgroud)
属性上也会出现此问题.
// Property case.
type [<AbstractClass>] BaseClass2<'x>() = …Run Code Online (Sandbox Code Playgroud) 有一个接口(比如IA),一个接口IA的实现(比如Base),以及一个派生类Base(比如Derived),它覆盖了IA的抽象成员.现在,在重写成员的实现中,我想使用Base的成员的实现.但是,我不知道怎么写这样做.
这段代码说明了我的问题:
type Flag =
| F1 = 1
| F2 = 2
type IA =
abstract member A: Flag
type Base() =
interface IA with
member this.A = F1
type Derived() =
inherit Base()
interface IA with
override this.A = (* ? *)
// base.A ||| F2 // NG (Compile error that `A` isn't a member of `base`)
// (base :> IA).A ||| F2 // NG (Syntax error)
// (this :> IA).A ||| F2 // NG (Infinite recursion)
Run Code Online (Sandbox Code Playgroud)