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 VAA21178; Thu, 29 Aug 2002 21:10: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 VAA21147 for ; Thu, 29 Aug 2002 21:10:41 +0200 (MET DST) Received: from smtp.noos.fr (lafontaine.noos.net [212.198.2.72]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g7TJ7fX16256 for ; Thu, 29 Aug 2002 21:07:55 +0200 (MET DST) Received: (qmail 2294029 invoked by uid 0); 29 Aug 2002 19:05:24 -0000 Received: from unknown (HELO noos.fr) ([81.65.61.57]) (envelope-sender ) by 212.198.2.72 (qmail-ldap-1.03) with SMTP for ; 29 Aug 2002 19:05:24 -0000 Message-ID: <3D6E7074.4D9D4273@noos.fr> Date: Thu, 29 Aug 2002 21:05:24 +0200 From: nadji@noos.fr X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.18 i686) X-Accept-Language: en MIME-Version: 1.0 To: "caml-list@inria.fr" Subject: Re: [Caml-list] polymorphic variant question References: <3D6E45DA.51D99F9F@noos.fr> <87znv5lh60.dlv@wanadoo.fr> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Thanks for all the answers but I search a more systematic one. In fact this was a (too) stripped version of a problem that is occuring quite frequently since I use a lot of pm. Imagine I have a type : type t = [`a|`b|`c] And I have a function f whose *infered* type is [`a|`b] -> unit I would like the compiler to know that (a semantically equivalent code as) function `c -> () | x -> f x is correct, without having to precise all the variant that x could be. (that is, without saying : function `c -> () | `a|`b as x -> f x nor type ab = [`a|`b] type t = [ab | `c] function `c -> () | #ab as x -> f x ) I don't want to write type annotations all around because - my pm are quite large - a lot of functions like f are not published in my interface - I think OCaml should be smart enough to do this TIA, Nadji Remi VANICAT wrote: > 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 ------------------- 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