From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=AWL,DNS_FROM_RFC_POST autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 0FDEFBC6A for ; Tue, 7 Nov 2006 01:00:44 +0100 (CET) Received: from out1.smtp.messagingengine.com (out1.smtp.messagingengine.com [66.111.4.25]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id kA700dH6008771 for ; Tue, 7 Nov 2006 01:00:43 +0100 Received: from db2.internal (db2.internal [10.202.2.12]) by frontend1.messagingengine.com (Postfix) with ESMTP id 4878DDC11F6; Mon, 6 Nov 2006 19:00:31 -0500 (EST) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by db2.internal (MEProxy); Mon, 06 Nov 2006 19:00:33 -0500 X-Sasl-enc: GRfl696T19B65wdzqBooAhmLG+VXxV9SHJWdwckG5NOf 1162857632 Received: from [172.16.112.115] (burnham.ljcrf.edu [192.231.106.2]) by mail.messagingengine.com (Postfix) with ESMTP id 68FF4762C; Mon, 6 Nov 2006 19:00:32 -0500 (EST) Date: Mon, 6 Nov 2006 15:59:55 -0800 (PST) From: Martin Jambon X-X-Sender: martin@localhost To: Serge Aleynikov Cc: caml-list@inria.fr Subject: Re: [Caml-list] parameterized pattern In-Reply-To: <454FA5F8.5030106@hq.idt.net> Message-ID: References: <454FA5F8.5030106@hq.idt.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-j-chkmail-Score: MSGID : 454FCCA7.001 on discorde : j-chkmail score : X : 0/20 1 X-Miltered: at discorde with ID 454FCCA7.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; ocaml's:01 ocaml:01 ocaml:01 1977:98 1.0:98 1.0:98 wrote:01 wrote:01 caml-list:01 jambon:01 jambon:01 match:02 match:02 string:02 string:02 On Mon, 6 Nov 2006, Serge Aleynikov wrote: > Hi, > > The section 6.6 of OCaml's manual introduces a notion of "Parenthesized > patterns". > > I couldn't find any examples on how to use this feature, and brute-force > approach doesn't work: > > # match 1.0 with > (y : float) -> print_float y > | (s : string) -> print_string s;; > This pattern matches values of type string > but is here used to match values of type float > # > > Could anyone point at a suitable resource? What you wrote is equivalent to: match ((1.0 : float) : string) with y -> print_float y | s -> print_string s In OCaml, match-with is a test against the structure of a value, not its type. What you want to do is not currently possible in OCaml. Martin -- Martin Jambon, PhD http://martin.jambon.free.fr