base
doA() を呼び出せるように、適切なインターフェイス タイプ (つまり)にアップキャストしようとすると、解析エラーが発生しA
ます。base
( http://cs.hubfs.net/topic/None/58670 ) が多少特殊であることは認識していますが、これまでのところ、この特定の問題の回避策を見つけることができませんでした。
助言がありますか?
type A =
abstract member doA : unit -> string
type ConcreteA() =
interface A with
member this.doA() = "a"
type ExtA() =
inherit ConcreteA()
interface A with
override this.doA() = "ex" // + (base :> A).doA() -> parse error (unexpected symbol ':>' in expression)
((new ExtA()) :> A).doA() // output: ex
動作する C# に相当するもの:
public interface A
{
string doA();
}
public class ConcreteA : A {
public virtual string doA() { return "a"; }
}
public class ExtA : ConcreteA {
public override string doA() { return "ex" + base.doA(); }
}
new ExtA().doA(); // output: exa