如何在f#构造函数中声明类型别名?

时间:2019-07-18 09:01:46

标签: f#

type Entity =
    abstract member newEntity: Entity
    abstract member clearEntity : Entity
    abstract member lastEntity : Entity
    abstract member loadData: Entity
    abstract member saveData: Entity -> unit
    abstract member deleteData: Entity -> unit

有什么办法可以避免重复写实体词?

type Entity =
    type T = Entity
    abstract member newEntity: T
    abstract member clearEntity : T
    abstract member lastEntity : T
    abstract member loadData: T
    abstract member saveData: T -> unit
    abstract member deleteData: T -> unit

我想要这样的实现,Scala应该能够做到

1 个答案:

答案 0 :(得分:6)

您不能将类型声明放在另一个内部。您可以做的是进行相互递归的类型声明:

type Entity =
    abstract member newEntity: T
    abstract member clearEntity : T
    abstract member lastEntity : T
    abstract member loadData: T
    abstract member saveData: T -> unit
    abstract member deleteData: T -> unit

and T = Entity