Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: barnier@recherche.enac.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Variance constraint
Date: Tue, 20 Mar 2001 23:03:37 +0900	[thread overview]
Message-ID: <20010320230337P.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <3AB7529A.CBB24D0A@recherche.enac.fr>

> 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


      reply	other threads:[~2001-03-20 14:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-20 12:52 Nicolas barnier
2001-03-20 14:03 ` Jacques Garrigue [this message]

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=20010320230337P.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=barnier@recherche.enac.fr \
    --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