On Tue, 16 Aug 2005, skaller wrote:
> I think the original question really meant:
>
> Why aren't "fst" and "snd" properly generic??
Sorry for joining the discussion late, but I question the need for fst and
snd in general. Whenever I find I'm using these functons regularly, I
find that I'm using tuples when I should be using structures. This is
especially the case when I'm future proofing the data structure, i.e. I
want to be able to add fields later on without having to rewrite all the
code.
This is one of the things I like about Ocaml- the lack of golden hammers,
but the rich variety of tools available. A lot of languages do seem to
have golden hammer data structures especially- consider lists in Lisp or
associative arrays in Perl. The sure sign of a golden hammer data
structure is that it's the one you pick if you're not sure what data
structure you need. Now, Ocaml doesn't have one. Ocaml doesn't have any
one single data structure which is always the right one. Tuples,
structures, objects, variant types, arrays, and lists all have some
overlap, and some unique features. There is no golden hammer, but there
is a rich and powerful enough set of tools that I've yet to see a
situation where the right tool for the job wasn't at hand.
Brian