Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] functors and objects
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Damien <Damien.Pous@e...>
Subject: [Caml-list] functors and objects
Hello,

I would like to write something like

<<
class type o = 
object 
	method react: unit
end

module type O = 
sig
	type t :> o (* sigh... *)
end

module R(M: O) = 
struct
	let l: M.t list ref = []
	let register (o: M.t) = l := o :: !l
	let react() = List.iter (fun o -> o#react) !l
end
>>

and then, in a second layer, something like 

<<
class type o' = 
object 
	inherit o
	method render: unit
end

module type O' = 
sig
	type t :> o' 
end

module R(M: O') = 
struct
	include R(M)
	let render() = List.iter (fun o -> o#render) !l
end
>>

I tried all sort of tricks with #o, type 'a t = #o as 'a ...
but I didn't managed to to it :(
(without turning my objects into plain modules)

Any idea ?

Is it unsound to let a functor use an object type ?
(not to inherit from the class, 
just to use the methods of objects belonging to this type)

thanks,
damien

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners