From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA23591; Tue, 20 Mar 2001 15:01:39 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 PAA02065 for ; Tue, 20 Mar 2001 15:01:38 +0100 (MET) Received: from tet.kurims.kyoto-u.ac.jp (isdnppp2.kurims.kyoto-u.ac.jp [130.54.16.103]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f2KE1Z919036 for ; Tue, 20 Mar 2001 15:01:36 +0100 (MET) Received: from localhost (localhost [127.0.0.1]) by tet.kurims.kyoto-u.ac.jp (8.11.1/8.11.1) with ESMTP id f2KE3cv00645; Tue, 20 Mar 2001 23:03:38 +0900 (JST) (envelope-from garrigue@kurims.kyoto-u.ac.jp) To: barnier@recherche.enac.fr Cc: caml-list@inria.fr Subject: Re: [Caml-list] Variance constraint In-Reply-To: <3AB7529A.CBB24D0A@recherche.enac.fr> References: <3AB7529A.CBB24D0A@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: <20010320230337P.garrigue@kurims.kyoto-u.ac.jp> Date: Tue, 20 Mar 2001 23:03:37 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > I found the doc quite elusive on the subtle + and - notations > for variance and contravariance constraints of abstract types. > Can someone points out a good reference with examples that > adresses this issue ? Maybe Jacques Garrigue ? Sorry, there is nothing available currently. You can find annotations in a few libraries: the Map module in the standard library, the Raw module in LablGL, or the Gdk and Gtk modules in LablGTK. Basically, you normally only use annotations on abstract types (where no definition is provided) to describe the expected behaviour of the type with respect to subtyping. For instance, an immutable container type (like lists) will have a covariant type: type (+'a) container meaning that if s is a subtype of t then s container is a subtype of t container. On the other hand an acceptor will have a contravariant type: type (-'a) acceptor meaning that if s is a subtype of t then t acceptor is a subtype s acceptor. A type with no annotation is kept nonvariant, but there is no way to express that a type is both covariant of contravariant (i.e. that both subtypes and supertypes are ok): I don't really see any use for it... For concrete or abbreviation types, variance is automatically inferred, and variance annotations are only used to check that the type really has the expected variance. In particular they do not effectively restrict a type's variance. Example type (+'a) key = int will be accepted, but key will actually be both covariant and contraviant in 'a (which does not appear in the body). Hope this helps. Should I add this to the manual ? Jacques Garrigue ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr