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 NAA04817; Sat, 26 Jun 2004 13:17:29 +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 NAA04575 for ; Sat, 26 Jun 2004 13:17:28 +0200 (MET DST) Received: from ptb-relay01.plus.net (ptb-relay01.plus.net [212.159.14.212]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i5QBHSSH019933 for ; Sat, 26 Jun 2004 13:17:28 +0200 Received: from [80.229.56.224] (helo=chetara) by ptb-relay01.plus.net with esmtp (Exim) id 1BeBBX-00051W-U4 for caml-list@inria.fr; Sat, 26 Jun 2004 11:17:28 +0000 From: Jon Harrop To: "caml-list" Subject: [Caml-list] Pattern matching over elements at the front of a container Date: Sat, 26 Jun 2004 12:15:26 +0100 User-Agent: KMail/1.6.2 MIME-Version: 1.0 Content-Disposition: inline Message-Id: <200406261215.26971.postmaster@jdh30.plus.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 40DD5B48.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; postmaster:99 succinct:01 -tuple:01 lazily:01 arrays:01 ocaml:01 feasible:01 match:02 match:02 storing:03 alter:95 array:04 stuff:05 suspect:05 equivalent:05 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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? 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? 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? 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