[
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: | 2010-07-25 (11:51) |
From: | Christophe TROESTLER <Christophe.Troestler+ocaml@u...> |
Subject: | Re: [Caml-list] Encoding of (constructor * with * tuple) |
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 $B!H(BUniq$B!I(B constructor is NOT declared with a 4-tuple but with a single type $B!H(Bcolor$B!I(B. 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 $B!H(BUniq color$B!I(B since the constructor now expects 4 arguments. Best, C.