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 MAA14310; Sun, 18 Nov 2001 12:56:15 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA14077 for ; Sun, 18 Nov 2001 12:56:14 +0100 (MET) Received: from mail.mimuw.edu.pl (paf87.warszawa.sdi.tpnet.pl [217.96.225.87]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id fAIBu9v17859 for ; Sun, 18 Nov 2001 12:56:10 +0100 (MET) Received: (from news@localhost) by mail.mimuw.edu.pl (PLD/8.9.3) id MAA20554 for caml-list@inria.fr; Sun, 18 Nov 2001 12:57:04 +0100 X-Authentication-Warning: qrnik.zagroda: news set sender to Marcin 'Qrczak' Kowalczyk using -f From: "Marcin 'Qrczak' Kowalczyk" Subject: Re: [Caml-list] Re: [Q]: Co(ntra)variance and subtyping? Date: Sun, 18 Nov 2001 11:57:01 +0000 (UTC) Organization: Klub Nieszkodliwych =?iso-8859-2?Q?Manjak=F3w?= Message-ID: References: <20011117185051.A7607@qiao.in-berlin.de> <9t7v4d$gij$1@qrnik.zagroda> X-Trace: qrnik.zagroda 1006084621 20549 192.168.0.1 (18 Nov 2001 11:57:01 GMT) X-Complaints-To: abuse@localhost NNTP-Posting-Date: Sun, 18 Nov 2001 11:57:01 +0000 (UTC) User-Agent: slrn/0.9.7.2 (Linux) To: caml-list@inria.fr Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Disclaimer: I have no experience in OCaml's object system. Sun, 18 Nov 2001 10:16:36 +0100, Clemens Hintze pisze: > - In the context you have mentioned above: 'invariant' means the two > types have *no* relationship to each other, yes? Yes. > - If you believe that contravariance isn't generally particularly > useful, as you stated in the mail before, why can I flag some type > with (-'a) stating this is contravariant? What sense does this make? For a concrete type you have little choice: either the type definition allows covariant changes of the parameter type (list is an example of such type), or it allows contravariant changes (type 'a f = 'a -> unit is an example), or it doesn't allows any changes (array is an example). It follows either from type definition (in the case of algebraic types) or from primitive operations provided (for primitive types). The compiler infers variance of concrete types itself. Explicit annotations are useful for concrete types where it's not yet known which type will be substituted. Abstract types are invariant by default and in such case any type can be substituted (you will be able to make use of its variance only in places where it's known which concrete type is used). You can mark an abstract type as covariant and then only covariant concrete types can be substituted when matching a module to a module type. Similarly - contravariant. A concrete type can also allow both variances (if the type variable of its parameter is not used in its body). AFAIK there is no syntax to mark abstract types as such - it has little use anyway. > - What exactly are types and subtypes in OCaml? Subtypes are generated by object types (by including more methods, or having the same method names with subtypes as their types), by using a subtype as a parameter to a covariant type, by using a supertype as a parameter to a contravariant type, and from making this relation reflexive and transitive. I don't know if that's all. I'm not sure how polymorphic variant types interact with this. They are surely covariant wrt. argument types, but coercions which extend the type by including more variants can be implicit - they don't need the :> operator. -- __("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ QRCZAK ------------------- 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