Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Till Varoquaux <till.varoquaux@g...>
Subject: Re: [Caml-list] Feature request : Tuples vs. records
Another simple difference is that you have to declare the type of the
records whereas types of tupples can be infered. Since the typechecer
actually uses the type information given, you can use polymorphic
fields to implement general reccursivity.
I would also mention row polymorphisme and "mutable" as notable
differences. You could also note that they are not always
interchangeable: whilst you wouldn't want to define a new record type
for every tupple you use (very verbose), direct access to a defined
field and the "with" keyword (e.g let b={a with x=1}) make records
nice to handle large structures.

Till

On 2/22/07, Andreas Rossberg <rossberg@ps.uni-sb.de> wrote:
> skaller wrote:
> >
> >> 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).
> >
> > There's another difference in Ocaml: records
> > are nominally typed, tuples are structurally typed.
>
> In fact, these are closely related. In SML, tuples *are* records: the
> syntax (x,y) is merely syntactic sugar for {1=x, 2=y}, where 1 and 2 are
> numeric labels. Record projection #lab thus naturally applies to tuples.
> However, that definition of tuples requires structural record typing.
>
> --
> Andreas Rossberg, rossberg@ps.uni-sb.de
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>