Browse thread
[Caml-list] Pattern matching over elements at the front of a container
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2004-06-26 (11:17) |
From: | Jon Harrop <postmaster@j...> |
Subject: | [Caml-list] Pattern matching over elements at the front of a container |
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