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 JAA04599; Mon, 28 Jun 2004 09:57:12 +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 JAA04553 for ; Mon, 28 Jun 2004 09:57:11 +0200 (MET DST) Received: from beaune.inria.fr (beaune.inria.fr [128.93.8.3]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i5S7vASH002302 for ; Mon, 28 Jun 2004 09:57:10 +0200 Received: by beaune.inria.fr (8.8.8/1.1.22.3/14Sep99-0328PM) id JAA0000022734; Mon, 28 Jun 2004 09:57:09 +0200 (MET DST) Date: Mon, 28 Jun 2004 09:57:09 +0200 From: Luc Maranget To: Jon Harrop Cc: caml-list Subject: Re: [Caml-list] Pattern matching over elements at the front of a container Message-ID: <20040628095709.B17827@beaune.inria.fr> References: <200406261215.26971.postmaster@jdh30.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <200406261215.26971.postmaster@jdh30.plus.com>; from postmaster@jdh30.plus.com on Sat, Jun 26, 2004 at 12:15:26PM +0100 X-Miltered: at concorde with ID 40DFCF56.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 succinct:01 -tuple:01 lazily:01 non-linear:01 bug:01 faq:01 faq:01 beginner's:01 beginners:01 arrays:01 bin:01 compiler:01 caml-bugs:01 semantics:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, > > I'm currently storing stuff and things in a list. The ability to pattern match > over the first element or two using a succinct notation is, of course, nifty. > However, I'd like to replace my list with some other container, maybe an > array, maybe something of my own creation. What's the easiest way to keep my > ability to pattern match over the first few elements at the front of the > container? I could try to extract the first couple of elements and match over > a 2-tuple of "element option"s. Can a lazily evaluated stream help? How > expensive is this in terms of performance? Well, have a try, you may pay a little in performance, most of the time it does not matter. > > In the case of lists, you can match against the first two elements using the > pattern "a::b::_". As the "_" is not bound in the corresponding expression, > an equivalent notation could be invented for arrays in this case. Is this > feasible? Would anyone else find this useful? It is certainly feasible, whether it is worth including in the compiler is debatable... > > Also, is it not possible to alter the definition and implementation of OCaml > such that the pattern "(a, a)" is treated as "(a, b) when a=b"? Has this not > been done because the "=" is suspect? Just say No (to non-linear patterns) ! Basically and you can interpret this by saying << = is suspect >>, this apparently innocent addition is a radical change in semantics. > > Cheers, > Jon. > > ------------------- > 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 -- Luc Maranget ------------------- 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