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-23 (22:26) |
From: | Frédéric_Gava <gava@u...> |
Subject: | Re: [Caml-list] (int * int) <> int*int ? |
>No. There are cases where (int*int*int) is not the same as int*int*int. >Specifically, int*(int*int*int) is different than int*int*int*int. As a sub-part of a type, ok but I speak about general parentheses... >You keep trying to assume that the parentheses are purely syntactic- >they're not. I have never say that...you can read that i have write int->int->int <> (int->int)->int >So, in terms of representation: >type t = A of int * int >is represented in memory as > tag * int * int >while >type t' = B of (int * int) >is represented in memory as > tag * (int * int) >where in both cases tag is the tagging information added by the compiler. >Note that in the first case it's a three word structure (two ints and a >tag), while in the second case it's a two word structure (a tag and a >reference to a tuple of two ints). But where tag could represent information both int*int and (int*int) which is the same things (modulo an indirection which could be deleted at pattern-mathching). Morever, as Jon points of, variant types do not have this curious things due to boxed values...Also when you have build a pair, semantically you want to apply the constructor on this pair...because, there no partial applications of the constructors : for a constructor A of int*int you can not write (A 3) of type int->t (as in mini-ML or Haskell). I understand (and agree) the performances reasons, but I thinks that could be deleted since the only (that i see) case where the performances are differents is in the case of pattern-matching... >No. Because in the case of B, I can snag the tuple as an independent >peice of data. For example, I can write: > let f = function B x -> fst x;; >and it works. On the other hand, if I try to write: > let g = function A x -> fst x;; >this doesn't work- because the "tuple" in A doesn't really exist as an >independent data structure (it's been unboxed). Here, Ocaml is refusing >to allow a pointer into the middle of a structure (the GC algorithm thanks >you), and doesn't want to have to allocate a tuple to hold x (this >seriously complicates pattern matching). Peraps it complicates the pattern-matching but in the second case, x could be quickly and automatically build from (A x) because tags of tuples and of concrete types are close...and you avoid this curious construction (many years that I program in ocaml and curiously, never saw this things because always build the different parameters of the concrete constructor in different "variables" ;-) so I think that it is not a problem that appear many times in ocaml programs...some one always used the two differents constructions ?) FG