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 42CF8BC0A for ; Thu, 15 Feb 2007 14:41:36 +0100 (CET) Received: from sigma957.cis.mcmaster.ca (sigma957.CIS.mcmaster.ca [130.113.64.83]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1FDfZeq019777 for ; Thu, 15 Feb 2007 14:41:35 +0100 Received: from Dura7.UTS.McMaster.CA (dura7.UTS.mcmaster.ca [130.113.196.62]) by sigma957.cis.mcmaster.ca (8.13.7/8.13.7) with ESMTP id l1FDfEZn016344; Thu, 15 Feb 2007 08:41:34 -0500 (EST) Received: from cgpsrv2.cis.mcmaster.ca (univmail.CIS.mcmaster.ca [130.113.64.46]) by Dura7.UTS.McMaster.CA (8.13.7/8.13.7) with ESMTP id l1FDetNP023119; Thu, 15 Feb 2007 08:40:55 -0500 Received: from [74.109.166.109] (account carette@univmail.cis.mcmaster.ca HELO [192.168.1.101]) by cgpsrv2.cis.mcmaster.ca (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 162311484; Thu, 15 Feb 2007 08:40:56 -0500 Message-ID: <45D462EE.5040100@mcmaster.ca> Date: Thu, 15 Feb 2007 08:41:02 -0500 From: Jacques Carette Organization: McMaster University User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: skaller Cc: OCaml Subject: Re: [Caml-list] Patterns that evaluate References: <45D23608.4030104@mcmaster.ca> <45D37AD0.3090002@mcmaster.ca> <1171511618.13529.49.camel@rosella.wigram> In-Reply-To: <1171511618.13529.49.camel@rosella.wigram> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version-Mac: 4.7.1.128075, Antispam-Engine: 2.4.0.264935, Antispam-Data: 2007.2.15.51433 X-PerlMx-Spam: Gauge=IIIIIII, Probability=7%, Report='__CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __USER_AGENT 0' X-Miltered: at discorde with ID 45D4630F.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 generality:01 compiler:01 ocaml's:01 syntax:01 semantics:01 ocaml:01 globals:01 wrote:01 imho:01 caml-list:01 tuples:01 tail:01 argument:02 tend:02 skaller wrote: > It is a common wish, but has many problems IMHO. > First, it isn't very general. Fallacious argument: OCaml has records, so there is no need for tuples which are less general. Yet it has them. The point is to balance generality with convenience. That is why redundancy in a language may be a pain for the compiler writers, but can make a big difference to the users. Note that I was not suggesting, ever, that OCaml's current pattern-matching be 'broken' by blindly adding 'active' views. A different syntax would seem to make sense. > [...] and more generally > patterns from expressions, would be extremely fragile: > > let h = 1 in > match x with > | h :: t -> ... > > The meaning of this matching appears to be to match > a list starting with 1, binding t to the tail .. but > it all depends on whether t is a symbol in the context > of this fragment. The meaning would change if t were > not in the context and a programmer introduced it: > Sure. But that is the normal semantics of the rest of OCaml you're complaining about here! Yes, having a pattern-matching mechanism which is context dependent (like the rest of OCaml) instead of always working in an empty environment is different, that is expected. Personally, I find that I don't write programs with a lot of variable shadowing, I tend to use new names in matches. And no globals. I consider them both to be bad style ;-) > Thirdly it leaves open the issue of non-linear patterns: > | x , x -> ... > If x had a value, this would not be a problem at all. It is only a problem in the 'binding' case. > I also often match nasty patterns in many places and really > wish I could name them: > > pattern p(x) = C x > match e with | p(x) -> ... > > doesn't provide active patterns, but it would be quite useful. > Agreed, that would be nice. Regarding Jay-style matching: I was _expecting_ some kind of active patterns to work, I _want_ Jay style patterns. Very different! Jacques