From: Brian Hurt <bhurt@spnz.org>
To: "Frédéric Gava" <gava@univ-paris12.fr>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] (int * int) <> int*int ?
Date: Thu, 23 Feb 2006 15:57:23 -0600 (CST) [thread overview]
Message-ID: <Pine.LNX.4.63.0602231546080.9569@localhost.localdomain> (raw)
In-Reply-To: <00e301c638c0$5368ef20$1f570b50@mshome.net>
[-- Attachment #1: Type: TEXT/PLAIN, Size: 2639 bytes --]
On Thu, 23 Feb 2006, Frédéric Gava wrote:
>> This isn't correct- the same problem shows up in the difference between:
>> int*int*int and int*(int*int)- i.e. the difference between (1,2,3) and
>> (1,(2,3)). In the first case (in both examples) I have a three element
>> tuple, in the second case I have a two element tuple whose second element
>> is also a two element tuple (and thus I have the layer of indirection).
>
> Hum, no...here we have three (int) or two (one int and one pair) elements.
> In the concrete type case, we have two elements (and both cases pair because
> in both case A (2,3) works fine) and it is a problem of curryfication which
> is not justify. (int*int*int)=int*int*int everywhere and also
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.
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).
You keep trying to assume that the parentheses are purely syntactic-
they're not.
>> I can often
>> save copying information (and storing the duplicate information) if I can
>> add the level of indirection- this is important if I'm copying the
>> information a lot. On the other hand, if the information isn't being
>> duplicated a lot, then I can save memory by not having the extra level of
>> indirection.
>
> This is why I thinks that the case (int*int) is not justify if there is no
> partial application of the concrete constructors (because the level of
> indirection could be avoid at the time of pattern-matching : you quickly
> modify the data of the concrete type to have a tuple...).
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).
Brian
next prev parent reply other threads:[~2006-02-23 21:57 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-23 17:28 Frédéric Gava
2006-02-23 18:33 ` [Caml-list] " Eric Cooper
2006-02-23 19:03 ` Martin Jambon
2006-02-23 19:07 ` Frédéric Gava
2006-02-23 20:15 ` Brian Hurt
2006-02-23 21:30 ` Frédéric Gava
2006-02-23 21:57 ` Brian Hurt [this message]
2006-02-23 22:30 ` Frédéric Gava
2006-02-23 22:50 ` Brian Hurt
2006-02-23 23:07 ` Frédéric Gava
2006-02-24 8:38 ` Alessandro Baretta
2006-02-24 12:59 ` Damien Doligez
2006-02-23 18:33 ` Thomas Fischbacher
2006-02-23 18:56 ` David Brown
2006-02-23 19:24 ` Frédéric Gava
2006-02-23 19:37 ` Frédéric Gava
2006-02-23 19:45 ` Frédéric Gava
2006-02-24 0:01 ` Jacques Garrigue
2006-02-24 0:18 ` Lukasz Stafiniak
2006-02-24 2:17 ` Jacques Garrigue
2006-02-24 13:07 ` Alain Frisch
2006-02-25 17:42 ` Vincent Balat
2006-02-25 18:30 ` Nicolas Pouillard
2006-02-25 19:09 ` Richard Jones
2006-03-01 12:48 ` Nicolas Pouillard
2006-02-25 23:17 ` Christophe TROESTLER
2006-03-01 13:01 ` Nicolas Pouillard
2006-02-27 11:14 ` camlp4 renovation [was: [Caml-list] (int * int) <> int*int ?] Hendrik Tews
2006-02-24 13:39 ` [Caml-list] (int * int) <> int*int ? Nicolas Cannasse
2006-02-24 14:49 ` Frédéric Gava
2006-02-24 8:27 ` also for tagged records? [Was: Re: [Caml-list] (int * int) <> int*int ?] Sebastian Egner
2006-02-24 14:01 ` Thomas Fischbacher
2006-02-23 20:58 ` [Caml-list] (int * int) <> int*int ? Jon Harrop
2006-02-23 21:36 ` Frédéric Gava
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.63.0602231546080.9569@localhost.localdomain \
--to=bhurt@spnz.org \
--cc=caml-list@yquem.inria.fr \
--cc=gava@univ-paris12.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox