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:25)
From: David Teller <David.Teller@e...>
Subject: Feature request : Tuples vs. records
A long time ago, I used to believe that there was a large difference 
between tuples and records: tuples constructors/patterns use the order 
of their arguments to determine where they fit in the data structure, 
while records use the name of arguments. And then, labels arrived and 
somehow made possible to use either style when it comes to defining and 
applying functions.

Now, of course, I have the task of teaching OCaml to students. When it 
comes to explaining the difference between tuples and records, I'm 
suddenly unsure. Why is there a difference at all ? Aren't records the 
same thing as tuples with labels ? Couldn't/shouldn't the next version 
of OCaml uniformize both syntaxes and get us rid of {} once and for all ?

I envision something like
# (1,2);;
- : int * int = (1, 2)

# let pair_2 = (~x:1, ~y:2);;
pair_2 : x:int * y:int = (1, 2)

# let pair_3 = (~y:2, ~x:1);;
pair_3 : y:int * x:int = (2, 1)    (*or perhaps normalisation, say based 
on the lexicographical order of labels*)

# pair_2 = pair_3;; (*structural equality*)

# match pair_2 with (~y:y, ~x:x) -> (x,y);;
- : int * int = (1, 2)

Is anything such considered ?