Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] [Q]: Co(ntra)variance and subtyping?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Remi VANICAT <vanicat@l...>
Subject: Re: [Caml-list] Re: [Q]: Co(ntra)variance and subtyping?
Alain Frisch <frisch@clipper.ens.fr> writes:

> Now, if you don't have the definition of a type constructor - say
> it is an abstract type from your point of view -
> you can't tell what its variance is w.r.t one of its arguments.
> So OCaml allows to specify this information in module interface;
> for instance, in map.mli:
> 
> module type S =
>   sig
>     type key
>           (* The type of the map keys. *)
>     type (+'a) t
>           (* The type of maps from type [key] to type ['a]. *)
> ...
> 
> 
> The '+' means that type t is covariant: a map from type key to type
> t1 can be coerced to a map from type key to type t2 if and only
> if t1 is a subtype of t2.
> 
> (I don't know why other modules such as Queue do not give variance
> information ...)

because Queue are neither covariant nor contravariant :
- a Queue contain things, so it can't be contravariant,
- you can add things to queue, so it can't be covariant
infact, most of the mutable thing are neither contravariant nor
covariant. 
-- 
Rémi Vanicat
vanicat@labri.u-bordeaux.fr
http://dept-info.labri.u-bordeaux.fr/~vanicat
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr