From: Christophe TROESTLER <Christophe.Troestler+ocaml@umh.ac.be>
To: rixed@happyleptic.org
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Encoding of (constructor * with * tuple)
Date: Sun, 25 Jul 2010 13:51:39 +0200 (CEST) [thread overview]
Message-ID: <20100725.135139.32716340832275763.Christophe.Troestler+ocaml@umons.ac.be> (raw)
In-Reply-To: <20100725105332.GA4771@happyleptic.org>
On Sun, 25 Jul 2010 12:53:35 +0200, wrote:
>
> Hello list.
>
> I'm using ocaml version 3.12.0+beta1, and reading the manual here :
>
> http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html#toc130
>
> I have this datatype :
>
> type color_specs = Array of vertex_array | Uniq of color
>
> where :
>
> type color = int * int * int * int
> type vertex_array = (nativeint, Bigarray.nativeint_elt, Bigarray.c_layout) Bigarray.Array2.t
>
> Values of type color_specs are passed to a C function.
>
>From the manual, I though that the value would be encoded in a block with a tag
> of 0 (for Array) or 1 (Uniq). If Array, wosize would be 1 and the first and
> only field would be a pointer to the bigarray, and if Uniq then the wosize
> would be 4 and the four fields would be the unboxed integers.
>
> But apparently I'm wrong since for the Uniq case the wosize is still
> 1 and the first field points to the tupple of 4 ints which is
> allocated separately, despite that the manual clearly says :
> "Non-constant constructors declared with a n-tuple as argument are
> represented by a block of size n, tagged with the constructor
> number; the n fields contain the components of its tuple argument."
Your “Uniq” constructor is NOT declared with a 4-tuple but with a
single type “color”. Hence the additional indirection. To have the
expected behavior, you must declare
type color_specs = Array of vertex_array | Uniq of int * int * int * int
(NOT
type color_specs = Array of vertex_array | Uniq of (int * int * int * int) !)
The drawback is that you cannot extract the color as a single value
“Uniq color” since the constructor now expects 4 arguments.
Best,
C.
prev parent reply other threads:[~2010-07-25 11:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-25 10:53 rixed
2010-07-25 11:51 ` Christophe TROESTLER [this message]
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=20100725.135139.32716340832275763.Christophe.Troestler+ocaml@umons.ac.be \
--to=christophe.troestler+ocaml@umh.ac.be \
--cc=caml-list@yquem.inria.fr \
--cc=rixed@happyleptic.org \
/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