Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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
tuple).

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

Dave