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 BAA25865; Mon, 19 Nov 2001 01:34:47 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA25810 for ; Mon, 19 Nov 2001 01:34:46 +0100 (MET) Received: from favie.faith.gr.jp (favie.faith.gr.jp [61.127.175.250]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id fAJ0Yev28317 for ; Mon, 19 Nov 2001 01:34:44 +0100 (MET) Received: from localhost (dhcp7.faith.gr.jp [192.168.1.17]) by favie.faith.gr.jp (8.9.3/8.9.3) with ESMTP id JAA25478; Mon, 19 Nov 2001 09:33:50 +0900 To: pixel@mandrakesoft.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] [Q]: Co(ntra)variance and subtyping? In-Reply-To: References: <20011116203745.A59514@qiao.in-berlin.de> <002001c17035$c722aa80$3363e195@pazo> X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20011119093329G.garrigue@kurims.kyoto-u.ac.jp> Date: Mon, 19 Nov 2001 09:33:29 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Pixel > > 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 = > # (switch `On, switch `Whatever);; > - : _[> `Off | `On] * _[> `Off | `On | `Whatever] = `Off, `Whatever This, again, is row polymorphism, not subsumption. The difference between (row/parametric) polymorphism and subsumption is that for the former you must explicitely leave some free variable in the type (the presence of which is proved by the "as 'a" or "_"), while the latter also works on ground types (without variables). Both polymorphic variants and objects uss both polymorphism and subtyping, but without implicit subsumption. > > 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 No, feasible should be defined more precisely :-) In the ML world, we mean complete type inference. For this explicit coercions are indeed necessary. If you're satisfied with partial inference, then you may find disciplines where some coercions can be inferred. Cheers, Jacques Garrigue ------------------- 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