Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Pairs vs. Records
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-12-13 (20:26)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] Pairs vs. Records
> > This is very surprising indeed, because the OCaml compilers generate
> > *exactly the same code* for building/accessing tuples and for
> > building/accessing records (with no mutable fields).
> I guess you know this better than I ;) but one can observe difference in
> generated code with pattern matching:
> # fun x y -> match (x,y) with (a,b) -> a + b;;
> # fun x y -> match {row=x;col=y} with {row=a;col=b} -> a + b;;

Actually, you're correct.  I was thinking in terms of using records or
tuples inside data structures, but it's true that there are two
"toplevel" uses of tuples that are optimized specially: one is for 
matching multiple values, as in your first example above; the other
(specific to ocamlopt) is when passing a tuple of arguments to a known
function that expects a tuple of the same size, e.g.

        let f (x, y) = ...
        ... f (e1, e2) ...

Here, ocamlopt can avoid the construction of the pair, but similar
code using records instead of pairs will not be optimized.

Sorry for spreading misinformation :-)

- Xavier Leroy
Bug reports:  FAQ:
To unsubscribe, mail  Archives: