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: Re: [Caml-list] functors and objects
On Thu, 05 Feb 2004 18:18:45 +0900 Jacques Garrigue wrote:

> Because instanciation/specialization only works for values, not for
> types.
> This is reasonable enough: once you have defined a type, you may use
> it both in covariant and contravariant positions, so allowing to
> specialize it would be unsound.
> (So, yes, in the long run this is a soundness problem.)

I don't see the point :-(

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

can be read as

module type O =
sig
	type ellipsis (* abstract *)
	type t = " <o; ellipsis> "
end

therefore, a functor F(M: O) cannot create objects of type t without the
help of M. 

module F(M: O) = 
struct
	(* correct invariant use *)
	let l: M.t list ref  = ref []   

	(* correct covariant use *)
	let get: unit -> M.t list = fun () -> !l

	(* correct contravariant use *)
	let add: M.t -> unit = fun o -> l := o : !l 

	(* unsound has type `unit -> o' but not `unit -> M.t' *)
	let unsound() = new object method react = () end 
end

where is it wrong ?

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