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 SAA06695; Sat, 17 Nov 2001 18:55:05 +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 SAA06420 for ; Sat, 17 Nov 2001 18:55:04 +0100 (MET) Received: from gnu.in-berlin.de (gnu.in-berlin.de [192.109.42.4]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id fAHHt3922158 for ; Sat, 17 Nov 2001 18:55:03 +0100 (MET) Received: from hirsch.in-berlin.de (root@hirsch.colt.in-berlin.de [213.61.118.6]) by gnu.in-berlin.de (8.10.1/8.10.1) with ESMTP id fAHHt3710929 for ; Sat, 17 Nov 2001 18:55:03 +0100 (CET) (envelope-from cle@qiao.in-berlin.de) X-Envelope-From: cle@qiao.in-berlin.de X-Envelope-To: Received: from hirsch.in-berlin.de (uucp@localhost [127.0.0.1]) by hirsch.in-berlin.de (8.12.1/8.12.1/Debian -2) with ESMTP id fAHHt1Z6023817 for ; Sat, 17 Nov 2001 18:55:02 +0100 Received: (from uucp@localhost) by hirsch.in-berlin.de (8.12.1/8.12.1/Debian -2) with UUCP id fAHHt1N5023804 for caml-list@inria.fr; Sat, 17 Nov 2001 18:55:01 +0100 Received: (qmail 8799 invoked by uid 500); 17 Nov 2001 17:50:51 -0000 Date: Sat, 17 Nov 2001 18:50:51 +0100 From: Clemens Hintze To: caml-list@inria.fr Subject: [Caml-list] Re: [Q]: Co(ntra)variance and subtyping? Message-ID: <20011117185051.A7607@qiao.in-berlin.de> References: <20011116203745.A59514@qiao.in-berlin.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.19i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Mark, let me first thank you for trying to answer my question. But unfortunately I am still not convinced, that I properly understood it ... On Sun, Nov 18, 2001 at 01:18:22AM +1100, Mark Wotton wrote: > On Fri, 16 Nov 2001, Clemens Hintze wrote: > > > Two things I would like to ask you right now: > > > > - What does subtyping exactly mean in OCaml resp. functional > > programming? > > - What means covariance and contravariance of types and subtypes? > > Not being an Ocaml guru, I shan't attempt the first question. > The second's pretty easy, though: covariance is the sane way of doing OO, > and contravariance is bizarre. (Right, if there's any Eiffel devotees on > here, I've just started a flamewar. :) I am not a Eiffel devotee, so nothing to fear here from me ;-) > Seriously: contravariance breaks the assumption that a subtype is capable > of everything that its parent can do. Essentially, it allows you to narrow > arguments to functions: to use some weird eiffelish pseudocode i had > lying around, you can do this. As I have understood, co(ntra)variance has someting to do with types and not with classes, right? And classes in OCaml are not types, right too? So it should not an issue about subclassing, if I understood correctly. So there has to be more about these, as only in area of OOP, shouldn't it? I can understand your explanation, though, but I fear that there is something more that is not covered by this example. What I have found during investigating this question via google and the mailinglist archive was this: - Covariance means that a specialized class also specialize the arguments of overloaded methods. You use 'narrow' instead of 'specializing' ... - Contravariance, however, is generalizing arguments of overloaded methods in specialized classes. So in this light, your example should demonstrate covariance, isn't it? But what I do not like in the explanation above, is that it also only refer to OOP and not types. Another explanation I've found, was (a --> b means a subtypes b): - Covariance means, that if t' --> t ==> t' list --> t list - Contravariance, however, if t' --> t ==> t list --> t' list This explanation is not based on OOP, fine! But to be honest, I do not understand this explanation nor its consequences. I would not be able right now, to build an example describing this above ... :-( And then there is still the term 'invariance' that I've even not asked so far (hoping it will explain itself if I had understand the other variances so far) :-/ So I need the explanation about type, subtype, co(ntra)variance, invariance and all these in OO and non-OO in OCaml. > It's an odd thing: most of the posts with apologies for bad English I've > seen on Usenet have been flawless as far as composition goes. Thank you for this :-) I know that my english should be good enough for being understood. But sometimes, some wrong phrases seem to spring in, and other feel necessary to flame me, then. So if I am new to a group, I want to state, that I am not a native speaker, hoping others will be mercy instead of flaming me :-) Ciao, Clemens -- Clemens Hintze mailto: c.hintze@gmx.net ------------------- 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