嵌套的通用接口类型

莫森

给定以下接口:

type A<'t> =
    abstract Scratch: 't

如何简单地创建这样的界面:

type X<A<'t>> =
    abstract f: A<'t>

我也尝试过这个:

type X<'t,'y when 'y:A<'t>> =
    abstract f: 'y

还有这个:

type X<'t,A<'t>> =
    abstract f: A<'t>

但没有一个对我有用。

时报

如果您希望将其作为界面,请尝试以下操作:

type IA<'a> =
    abstract Scratch: 'a

type IX<'a, 'b when 'a :> IA<'b>> = 
    abstract F: 'a

type RealA() = 
    interface IA<int> with
        member __.Scratch = 1

type RealX = 
    interface IX<RealA, int> with
        member __.F = RealA()

如果要抽象类:

[<AbstractClass>]
type A<'a>() = 
    abstract member Scratch: 'a

[<AbstractClass>]
type X<'a, 'b when 'a :> A<'b>>() = 
    abstract F: 'a

type RealA'() = 
    inherit A<int>()
    override __.Scratch = 1

type RealX'() = 
    inherit X<RealA', int>()
    override __.F = RealA'()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章