【发布时间】:2010-01-02 22:42:23
【问题描述】:
我在 OCaml 中有这两个类
class type ['a] collection =
object
method add : 'a -> unit
method clear : unit -> unit
method iterator : unit -> 'a iterator
method remove : 'a -> unit
end
class type ['a] iterator =
object
method hasNext : unit -> bool
method next : unit -> 'a
end
我需要创建两个具体类['a] queue 的collection 子类型和['a] iterator_queue iterator 的子类型。
我主要想知道如何定义方法iterator : unit -> 'a iterator,因为我看不到这两种类型如何连接,['a] iterator_queue 是否必须从两个抽象类型继承?还是我应该采取不同的方式。
【问题讨论】:
标签: class collections iterator ocaml