English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Pattern matching over elements at the front of a container
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ 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?


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