From: Pixel <pixel@mandrakesoft.com>
To: "Andreas Rossberg" <rossberg@ps.uni-sb.de>
Cc: "Clemens Hintze" <c.hintze@gmx.net>, <caml-list@inria.fr>
Subject: Re: [Caml-list] [Q]: Co(ntra)variance and subtyping?
Date: 18 Nov 2001 22:22:56 +0100 [thread overview]
Message-ID: <ly7ksnzscv.fsf@leia.mandrakesoft.com> (raw)
In-Reply-To: <002001c17035$c722aa80$3363e195@pazo>
"Andreas Rossberg" <AndreasRossberg@web.de> writes:
> > - What does subtyping exactly mean in OCaml resp. functional
> > programming?
>
> OCaml has two separate notions of subtyping:
>
> - in the core language, to support objects
> - in the module language, for signature matching
>
> While subtyping for module types is rather standard from a superficial point
> of view, OCaml's treatment of subtyping in the core language is somewhat
> special because it does not provide so-called subsumption.
well, you forgot polymorphic variants, which do use subsumption:
# let switch = function `On -> `Off | x -> x;;
val switch : ([> `Off | `On] as 'a) -> 'a = <fun>
# (switch `On, switch `Whatever);;
- : _[> `Off | `On] * _[> `Off | `On | `Whatever] = `Off, `Whatever
> Subsumption means
> that wherever a value of type t is expected you may freely provide a value
> of some subtype t'. This is not the case in OCaml: you have to explicitly
> coerce the value to the required supertype first. This is necessary to make
> type inference feasible.
necessary is a small overstatement ;p
[...]
> The most important type constructor is "->", which has the following
> subtyping rule:
>
> t' < t and u' < u => (t -> u') < (t' -> u)
>
> Note the order of t and t' here: it goes in the opposite direction!
> Functions are covariant in their result type, but contravariant in their
> argument type. This may seem a bit funny at first (and in fact there are
> major programming languages that still insist on getting it plainly wrong -
> you already know one ;-)
if you want more about it, read the nice paper from Giuseppe Castagna:
Covariance And Contravariance: conflict Without A Cause
http://citeseer.nj.nec.com/castagna95covariance.html
-------------------
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
next prev parent reply other threads:[~2001-11-18 21:25 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-16 19:37 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
2001-11-18 13:34 ` [Caml-list] " Andreas Rossberg
2001-11-18 21:22 ` Pixel [this message]
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=ly7ksnzscv.fsf@leia.mandrakesoft.com \
--to=pixel@mandrakesoft.com \
--cc=c.hintze@gmx.net \
--cc=caml-list@inria.fr \
--cc=rossberg@ps.uni-sb.de \
/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