From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id IAA24241 for caml-red; Tue, 13 Feb 2001 08:19:33 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA17042 for ; Tue, 13 Feb 2001 00:45:57 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f1CNjtf27459 for ; Tue, 13 Feb 2001 00:45:56 +0100 (MET) Received: from tet.kurims.kyoto-u.ac.jp (isdnppp2.kurims.kyoto-u.ac.jp [130.54.16.103]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id IAA07724; Tue, 13 Feb 2001 08:45:47 +0900 (JST) Received: from localhost (localhost [127.0.0.1]) by tet.kurims.kyoto-u.ac.jp (8.11.1/8.11.1) with ESMTP id f1CNl5G03100; Tue, 13 Feb 2001 08:47:05 +0900 (JST) (envelope-from garrigue@kurims.kyoto-u.ac.jp) To: barnier@recherche.enac.fr, qrczak@knm.org.pl Cc: caml-list@inria.fr Subject: Re: OCaml's long range graphical direction? In-Reply-To: <3A87F898.D0D00FF7@recherche.enac.fr> References: <20010209102801K.garrigue@kurims.kyoto-u.ac.jp> <3A87F898.D0D00FF7@recherche.enac.fr> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20010213084705X.garrigue@kurims.kyoto-u.ac.jp> Date: Tue, 13 Feb 2001 08:47:05 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: weis@pauillac.inria.fr From: Nicolas barnier > Marcin 'Qrczak' Kowalczyk wrote: > > > > What are variance annotations in OCaml? > > Perniciously stolen on the OCaml CVS server (file "Changes"), but I lack > the new doc ;-): > > Objective Caml 3.01: > -------------------- > > New language features: > - Variables are allowed in "or" patterns, e.g. > match l with [t] | [_;t] -> ... t ... > - "include " to re-export all components of a > structure inside another structure. > - Variance annotation on parameters of type declarations, e.g. > type (+'a,-'b,'c) t (covariant in 'a, contravariant in 'b, invariant in 'c) Yes, this is the syntax. Practically, this means that you can now mix object and variant subtyping with both datatypes and abstract types. For instance, suppose that you have two types c and d, d subtype of c. In ocaml 3.00, to coerce a list of d's to a list of c's, you would have to write List.map (fun x -> (x : d :> c)) l In ocaml 3.01, you can do it directly (l : d list :> c list) because list is a covariant type, which you can see from its definition. Not only that, but thanks to explicit variance annotations, even abstract datatypes, like maps from the Map module, can be traversed by subtyping. My remark on a lesser need for "hacked" coercions is a side-effect of that. Jacques Garrigue