caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Re: [Q]: Co(ntra)variance and subtyping?
Date: Sun, 18 Nov 2001 11:57:01 +0000 (UTC)	[thread overview]
Message-ID: <slrn9vf8gd.j3m.qrczak@qrnik.zagroda> (raw)
In-Reply-To: <9t7v4d$gij$1@qrnik.zagroda>

Disclaimer: I have no experience in OCaml's object system.

Sun, 18 Nov 2001 10:16:36 +0100, Clemens Hintze <cle-ocaml@qiao.in-berlin.de> 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


  parent reply	other threads:[~2001-11-18 11:56 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   ` [Caml-list] " Clemens Hintze
2001-11-17 23:17     ` 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 [this message]
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=slrn9vf8gd.j3m.qrczak@qrnik.zagroda \
    --to=qrczak@knm.org.pl \
    --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).