class ['a,'b] directory = object (self)
val items : (string,'a) Hashtbl.t = Hashtbl.create 11
val mutable subdirs : (string,'b) Hashtbl.t = Hashtbl.create 11
method add_item name x = Hashtbl.add items name x
method add_directory name x = Hashtbl.add subdirs name x
method iter f =
Hashtbl.iter (fun _ v -> f v) items ;
Hashtbl.iter (fun _ d -> d#iter f) subdirs
end
type 'a iterable = < iter : ('a -> unit) -> unit >
type 'a dir = ('a, 'a iterable) directory
type p = <pos:float*float>
type pc = <pos:float*float;color:string>
let d : p dir = new directory
let d' : pc dir = new directory
let () =
d#add_item "O" (object method pos = 0.,0. end) ;
d'#add_item "O_red" (object method pos = 0.,0. method color = "red" end) ;
d#add_directory "pc" (d' :> p iterable)