Browse thread
(int * int) <> int*int ?
[
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: | 2006-02-24 (08:29) |
From: | Sebastian Egner <sebastian.egner@p...> |
Subject: | also for tagged records? [Was: Re: [Caml-list] (int * int) <> int*int ?] |
> Consider > > type a = A of int * int > | B of (int * int) > > The result of A (3, 4) will be a two element tuple type tagged > appropriately for 'A' (in this case 0). > > The result of B (3, 4) will be a one element tuple type tagged for B, > with the single element referring to the two element tuple containing (3, > 4). > > Because tuples are generally immutable, there is little semantic > difference, but the compiler does have to keep track of which is which. In > most cases I would guess that 'A' would be more efficient (unless there are > lots of larger constructors sharing the same tuple). Is there a similar way as 'A' above for records? This isn't valid Ocaml: type a = A of {mutable xA: int; mutable yA: int} | B of xyB and xyB = {mutable xB: int; mutable yB: int} Background: I had a case (a search tree data strucuture) where the additional indirection results in a 30% runtime penalty, due to increased pointer chasing (cache misses). It is the way it is in Ocaml and probably hard to change, but I would like to understand if there are fundamental reasons for it to be necessary or not. See also: http://caml.inria.fr/pub/ml-archives/caml-list/2005/11/9a6dcbcb4f3b4c0ebe9cdf28ac3d289b.en.html Sebastian.