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 NAA10496; Thu, 29 Apr 2004 13:18:56 +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 NAA10732 for ; Thu, 29 Apr 2004 13:18:55 +0200 (MET DST) Received: from mta1.cl.cam.ac.uk (mta1.cl.cam.ac.uk [128.232.0.15]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i3TBIsYM020092 for ; Thu, 29 Apr 2004 13:18:54 +0200 Received: from astrocyte.cl.cam.ac.uk ([128.232.8.107] helo=cl.cam.ac.uk ident=[F5WPKgQpNGP9mIEkKzZ++8HhqIpCi907]) by mta1.cl.cam.ac.uk with esmtp (Exim 3.092 #1) id 1BJ9Z8-0005Rl-00 for caml-list@inria.fr; Thu, 29 Apr 2004 12:18:54 +0100 X-Mailer: exmh version 2.6.3-CL 04/04/2003 with nmh-1.0.4 X-Exmh-Isig-CompType: comp X-Exmh-Isig-Folder: cslists/caml To: caml-list@inria.fr Subject: [Caml-list] Documentation error - #myvariant Mime-Version: 1.0 Content-Type: text/plain Date: Thu, 29 Apr 2004 12:18:54 +0100 From: Keith Wansbrough Message-Id: X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; or-patterns:01 3.07:01 val:01 runtime:01 bool:01 bool:01 ocaml:01 ocaml:01 variants:01 int:01 int:01 rec:01 rec:01 polymorphic:01 string:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi.. the OCaml documentation, section 4.2 on polymorphic variants, Advanced use, explains that To make this even more confortable, you may use type definitions as abbreviations for or-patterns. That is, if you have defined type myvariant = [`Tag1 int | `Tag2 bool], then the pattern #myvariant is equivalent to writing (`Tag1(_ : int) | `Tag2(_ : bool)). But this is not correct! Consider type de = [`D | `E of de];; type def = [`D | `E of def | `F of def];; let rec deproc2 rfun = function | `D -> print_string "D"; `D | `E(x) -> print_string "E"; `E(rfun x) let rec deproc3 x = deproc2 deproc3 x let rec defproc2 rfun = function (* | (`D | `E(_)) as x -> deproc2 rfun x *) | #de as x -> deproc2 rfun x | `F(x) -> print_string "f"; `F(rfun x) let rec defproc3 : def -> def = fun x -> defproc2 defproc3 x This gives the following error (in OCaml 3.07+2): File "polyvar2.ml", line 19, characters 29-30: This expression has type def = [ `D | `E of def | `F of def ] but is here used with type [< `D | `E of de | `F of de ] Type def = [ `D | `E of def | `F of def ] is not compatible with type de = [ `D | `E of de ] (Note that the expression mentioned is the final x on the last line.) Replacing the #de line with the commented line above it, however, yields val defproc3 : def -> def = as expected. It looks to me like #de means (`D | `E(_:de)), rather than (`D | `E(_)) as I expected; except that I'm not even sure what `E(_:de) means in this case - does it do type-directed matching at runtime? Could the documentation please be made more accurate at this point? Thanks. --KW 8-) ------------------- 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