[
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: | 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: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr