type 'a subdir = < iter : ('a -> unit) -> unit >
class ['a] directory = object
val mutable items : (string*'a) list = []
val mutable subdirs : (string * 'a subdir) list = []
method add_item s i = items <- (s,i)::items
method add_directory s i = subdirs <- (s,i)::subdirs
method iter f =
List.iter (fun (_,x) -> f x) items ;
List.iter (fun (_,d) -> d#iter f) subdirs
end
type p = <pos:float*float>
type pc = <pos:float*float;color:string>
let d = new directory
let d' = new directory
let () =
d#add_item "o" (object method pos = 0.,0. end) ;
d'#add_item "pc" (object method pos = 0.,0. method color = "red" end) ;
d#add_directory "points colorés" (d' :> p subdir)