caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Clemens Hintze <cle-ocaml@qiao.in-berlin.de>
To: caml-list@inria.fr
Subject: [Caml-list] Re: [Q]: Co(ntra)variance and subtyping?
Date: Sat, 17 Nov 2001 18:50:51 +0100	[thread overview]
Message-ID: <20011117185051.A7607@qiao.in-berlin.de> (raw)
In-Reply-To: <Pine.LNX.4.21.0111180112020.27799-100000@hons.cs.usyd.edu.au>

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


  parent reply	other threads:[~2001-11-17 17:55 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-16 19:37 [Caml-list] " Clemens Hintze
2001-11-17 14:18 ` Mark Wotton
2001-11-17 14:55   ` Mark Wotton
2001-11-17 17:50   ` Clemens Hintze [this message]
2001-11-17 23:17     ` [Caml-list] " Mark Wotton
2001-11-18  9:16       ` Clemens Hintze
2001-11-18 13:18         ` Alain Frisch
2001-11-19  9:54           ` Remi VANICAT
     [not found]       ` <9t7v4d$gij$1@qrnik.zagroda>
2001-11-18 11:57         ` Marcin 'Qrczak' Kowalczyk
2001-11-18 13:34 ` [Caml-list] " Andreas Rossberg
2001-11-18 21:22   ` Pixel
2001-11-19  0:33     ` Jacques Garrigue
2001-11-18 22:35       ` David Gurr
2001-11-19  7:24         ` [Caml-list] " Clemens Hintze
2001-11-19 12:03           ` Markus Mottl
2001-11-19  8:29         ` [Caml-list] " Xavier Leroy
2001-11-19 11:03       ` Alain Frisch
2001-11-20  9:58         ` Didier Remy
2001-11-19 11:14       ` Pixel
2001-11-18 22:30   ` [Caml-list] Re: variance, subtyping and monads... oh, my! james woodyatt
2001-11-19  8:11     ` Francois Pottier
2001-11-19  9:02       ` james woodyatt
2001-11-19  9:58         ` Markus Mottl
2001-11-19 20:47           ` james woodyatt
2001-11-19 12:56       ` Frank Atanassow
2001-11-19 10:39     ` Andreas Rossberg
2001-11-19 12:21       ` Markus Mottl
2001-11-19 13:43         ` [Caml-list] Kylix and OCaml Christophe Raffalli
2001-11-20  2:05           ` Vitaly Lugovsky
2001-11-20  8:51             ` Christophe Raffalli
2001-11-22  1:42               ` Vitaly Lugovsky
2001-11-20 10:00             ` Benjamin Monate
2001-11-20 10:24               ` [Caml-list] [Bug in an interface between C++ and OCAML due to some pointer encapsulation] Sylvain Kerjean
2001-11-20 12:14             ` [Caml-list] Kylix and OCaml Maxence Guesdon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20011117185051.A7607@qiao.in-berlin.de \
    --to=cle-ocaml@qiao.in-berlin.de \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).