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.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 8FB94BC69 for ; Fri, 9 Mar 2007 03:02:10 +0100 (CET) Received: from ipmail03.adl2.internode.on.net (ipmail03.adl2.internode.on.net [203.16.214.135]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l292268s027926 for ; Fri, 9 Mar 2007 03:02:09 +0100 Received: from ppp19-103.lns2.syd7.internode.on.net (HELO [192.168.1.201]) ([59.167.19.103]) by ipmail03.adl2.internode.on.net with ESMTP; 09 Mar 2007 12:32:05 +1030 X-IronPort-AV: i="4.14,265,1170595800"; d="scan'208"; a="60151416:sNHT611858492" Subject: proposed extenion to patterns From: skaller To: caml-list@yquem.inria.fr Content-Type: text/plain Date: Fri, 09 Mar 2007 13:02:01 +1100 Message-Id: <1173405721.9499.13.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 45F0C01E.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 restrictive:01 inverted:01 sourceforge:01 rec:01 syntactic:01 variables:02 variables:02 match:02 let:03 let:03 pattern:04 pattern:04 restriction:05 variable:06 Pattern matches in Ocaml now allow alternatives within a branch subject to a restriction that all alternatives supply the same set of pattern variables (and of the same type). This is useful but still quite restrictive, for example: | A (i,j) | B i with j = 1 -> i + j cannot be coded, because there's no way to introduce the variable j. However this isn't really general enough either, because it can't HIDE variables! This form looks more general: | in A (h,k) let i = h and k = k | in B s let i = s + 1 let k = i These forms are inverted let/in constructions, with all the equivalent options (and, rec, and sequence). The variables h,k in the first alternative are hidden. The implementation is roughly syntactic sugar: match x with A (h,k) -> let i = h and k = k in i,k The 'with' form is a simplification, as is the usual form. Any comments on this idea? -- John Skaller Felix, successor to C++: http://felix.sf.net