English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
(int * int) <> int*int ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ 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 
> 4).
> Because tuples are generally immutable, there is little semantic
> difference, but the compiler does have to keep track of which is which. 
> most cases I would guess that 'A' would be more efficient (unless there 
> 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: