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-23 (18:56)
From: David Brown <caml-list2@d...>
Subject: Re: [Caml-list] (int * int) <> int*int ?
On Thu, Feb 23, 2006 at 06:28:48PM +0100, Frédéric Gava wrote:

> I understand that it'is force you to have a pair for A and not just a value
> of type pair but why this restriction ? It is not easy to explain why
> int*int <> (int*int).

As others have explained the represenatation is different.  The constructed
types themselves can contain multiple values (represented the same way as a


  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,

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).