Browse thread
Feature request : Tuples vs. records
[
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: | -- (:) |
| 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
"built-in").
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
datatype)
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).
Andrej