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 HAA12974; Wed, 21 Aug 2002 07:27:33 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id HAA12773 for ; Wed, 21 Aug 2002 07:27:32 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g7L5RUP12184 for ; Wed, 21 Aug 2002 07:27:31 +0200 (MET DST) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id OAA09006; Wed, 21 Aug 2002 14:27:24 +0900 (JST) To: nalexander@amavi.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] Naming polymorphic variant types In-Reply-To: <1413.207.194.7.18.1029903741.squirrel@mail.gx.ca> References: <1413.207.194.7.18.1029903741.squirrel@mail.gx.ca> X-Mailer: Mew version 1.94.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20020821142724W.garrigue@kurims.kyoto-u.ac.jp> Date: Wed, 21 Aug 2002 14:27:24 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: "Nick Alexander" > module type TEST = > sig > type outer = [ `A | `B] > and inner = [ `B] > val x : outer -> outer > val y : inner > end > module Test : TEST > # let p = Test.y;; > val p : Test.inner = `B > # let q = Test.x p;; > ^ > This expression has type Test.inner = [ `B] but is here used with type > Test.outer = [ `A | `B] > The first variant type does not allow tag(s) `A > > I'm confused. Can I get an explanation for why the parameter to a > function with a sum variant type needs all summands to be possible > arguments? Inner is a subtype of outer, but they cannot be unified (unification requires equality, not subtyping). You can get subtyping by writing explicit coercions: # let q = Test.x (p :> Test.outer);; val q : Test.outer = `A You can also give polymorphic types to your values in the interface: val x : [< outer] -> outer and val y : [> inner] are both valid, and one of them is enough to allow (Test.x p) without coercion. I.e., [< outer] can be unified with inner, and [> inner] can be unified with outer. Jacques Garrigue ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners