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
Feature request : Tuples vs. records
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-02-22 (10:38)
From: Andrej Bauer <Andrej.Bauer@f...>
Subject: Re: [Caml-list] Feature request : Tuples vs. records
Tuples and records are the same thing from the mathematical point of 
view, namely they are all just finite products. The only difference is 
that in once case the components are called 1, 2, 3, .., n and in the 
other the components have custom names. When I teach this stuff to 
students I first introduce tuples and later records. I tell them records 
are like tuples with named components, from which it follows that the 
order is not important. I also tell them (since they know Java), that 
records are a bit like simple-minded classes without inheritance, 
interfaces, methods and constructors (except they have constructors 

 From programmer's point of view it is better to have both tuples and 
records because they serve different purposes:

1) Tuples are syntactially "light-weight" and allow one to easily
    handle several values at the same time (without having to define a

2) Records allow the programmer to remember which component is what by
    naming them.

By the way, I always wondered why ocaml doesn't have generic projection 
operations from cartesian products (I belive they are writen #1, #2, #3 
... in SML).