caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "David Allsopp" <dra-news@metastack.com>
To: <caml-list@yquem.inria.fr>
Subject: Re: Execution time of class versus record
Date: Tue, 26 Jun 2007 08:36:24 +0100	[thread overview]
Message-ID: <002701c7b7c4$b3083100$6a7ba8c0@treble> (raw)
In-Reply-To: <20070626065522.6175FBC77@yquem.inria.fr>

On Jun 26, 2007, at 08:53 AM, Loup Vaillant wrote:
> > For the same reason, there is a difference between:
> >
> >   type t = A of int * int
> >
> > and:
> >
> >   type t = A of (int * int)
>
> Err, I don't get it : I see exactly the same thing (written twice) here.
>
> Are you telling that :
> type t = A of int * int   <==>   type t = (A of int) * int
>
>?

The type declarations are different - the top-level reports a different type
in each case!

The brackets matter because they tell O'Caml how many *arguments* the
constructor A will take and so affect the internal representation.

With the first type declaration, A(1, 2) is a 2-argument constructor and the
value will be represented internally as a 2-field block with tag 0 with
field 0 containing 1 and field 1 containing 2. This means that this code
wouldn't work:

    let foo = (1, 2)
    in
      A foo

but with the second type declaration it would.

With the second type declaration, A (1, 2) is a 1-argument constructor and
will be represented internally as a 1-field block with tag 0 with field 0
"pointing" to another 2-field block containing the 1 and 2.

Section #18.3.4 of the manual explains the internal representation
difference (esp. with ref to #18.3.6 where it is compared to Polymorphic
Variants) but I was sure that there was an explicit reference in the manual
to the difference between the type declarations but I can't find it now :(

The confusion arises because the notation for arguments of a constructor and
tuple construction look the same - I believe the "revised" syntax for O'Caml
changes the way these are declared to make it clearer but I've never looked
at it...


David


       reply	other threads:[~2007-06-26  7:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20070626065522.6175FBC77@yquem.inria.fr>
2007-06-26  7:36 ` David Allsopp [this message]
2007-06-26  8:05   ` [Caml-list] " Nicolas Pouillard
2007-06-24 15:20 tmp123
  -- strict thread matches above, loose matches on Subject: below --
2007-06-24 15:18 tmp123
2007-06-24 15:14 tmp123
2007-06-26 13:35 ` Sam Steingold

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='002701c7b7c4$b3083100$6a7ba8c0@treble' \
    --to=dra-news@metastack.com \
    --cc=caml-list@yquem.inria.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;
as well as URLs for NNTP newsgroup(s).