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 TAA18748; Thu, 29 Aug 2002 19:15:42 +0200 (MET DST) 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 TAA18693 for ; Thu, 29 Aug 2002 19:15:41 +0200 (MET DST) Received: from mel-rto3.wanadoo.fr (smtp-out-3.wanadoo.fr [193.252.19.233]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g7THFaX13206 for ; Thu, 29 Aug 2002 19:15:37 +0200 (MET DST) Received: from mel-rta10.wanadoo.fr (193.252.19.193) by mel-rto3.wanadoo.fr (6.5.007) id 3D49FC7D00B239CA for caml-list@inria.fr; Thu, 29 Aug 2002 19:15:35 +0200 Received: from debian (80.8.81.138) by mel-rta10.wanadoo.fr (6.5.007) id 3D49FFDD00AAC2CF for caml-list@inria.fr; Thu, 29 Aug 2002 19:15:35 +0200 Received: from moi by debian with local (Exim 3.35 #1 (Debian)) id 17kStr-0001CW-00 for ; Thu, 29 Aug 2002 19:16:07 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] polymorphic variant question References: <3D6E45DA.51D99F9F@noos.fr> Mail-Copy-To: never From: Remi VANICAT Date: Thu, 29 Aug 2002 19:16:07 +0200 In-Reply-To: <3D6E45DA.51D99F9F@noos.fr> (nadji@noos.fr's message of "Thu, 29 Aug 2002 18:03:38 +0200") Message-ID: <87znv5lh60.dlv@wanadoo.fr> User-Agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/21.2 (i386-debian-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk nadji@noos.fr writes: > Hi all, > > I am puzzled by the code below which doesn't work. > > # let f = function `B -> ();; > val f : [ `B] -> unit = > # let g x = match (x:[`A|`B]) with `A -> () | y -> f y;; > Characters 51-52: > let g x = match (x:[`A|`B]) with `A -> () | y -> f y;; > ^ > This expression has type [ `A | `B] but is here used with type [ `B] > (denoting the "y" from the "f y") > > How can I say to OCaml that "y" can't be of type `A ? well you can do the following : let g x = match (x:[`A|`B]) with `A -> () | `B as y -> f y;; for more complex case, you can do something like : type b = [ `B ] let g x = match (x:[`A|`B]) with `A -> () | #b as y -> f y;; -- Rémi Vanicat vanicat@labri.u-bordeaux.fr http://dept-info.labri.u-bordeaux.fr/~vanicat ------------------- 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