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 (21:18)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] (int * int) <> int*int ?
On Thursday 23 February 2006 17:28, Frédéric Gava wrote:
> is anybody can semantically explain why this 2 types are differents ?
> # type t=A of int*int and  t'= B of (int*int);;
> type t = A of int * int
> and t' = B of (int * int)

Only historical reasons, AFAIK. I do not believe this is necessary or that 
there is a logical reason for doing so.

> Morever I think that int*int=(int*int) in ML

Yes. I think it is logical to expect that.

> > And since the runtime representations are different, the types have to be
> > different.
> Wrong, you can the same representation but different types (e.g. int, char
> or many other examples)

I also believe that statement was wrong but I don't think you have provided 
counter-examples because the run-time representations are the same for the 
different types that you cite (rather than the converse).

Perhaps this is a better counterexample: the following functions "f" and "g" 
use different run-time representations but still have the same type:

# let f (a, b) = a+b
  let g (a, b as x) = a+b;;
val f : int * int -> int = <fun>
val g : int * int -> int = <fun>

	lea	-1(%eax, %ebx), %eax
	.align	16
	.globl	camlT2__g_61
	.type	camlT2__g_61,@function
	movl	4(%eax), %ebx
	movl	(%eax), %eax
	lea	-1(%eax, %ebx), %eax
	.align	16
	.globl	camlT2__entry
	.type	camlT2__entry,@function

I suspect a similar transformation could be done for variant type 

Also, note that this behaviour does not appear with polymorphic variants, 
where int * int <=> (int * int):

# type t = A of int * int | B of (int * int);;
type t = A of int * int | B of (int * int)
# type t = [ `A of int * int | `B of (int * int) ];;
type t = [ `A of int * int | `B of int * int ]

I assume the arguments of a polymorphic variant are always boxed...

Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists