From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 23ADCBBAF for ; Sun, 25 Jul 2010 13:51:45 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As0GAD/CS0zUNQXbmWdsb2JhbACDFJABjEcVAQEBAQEICwoHESIEAwECrWABgk8BjUMFgSODHXaIaA X-IronPort-AV: E=Sophos;i="4.55,257,1278280800"; d="scan'208";a="66905456" Received: from relay04ant.iops.be ([212.53.5.219]) by mail4-smtp-sop.national.inria.fr with ESMTP; 25 Jul 2010 13:51:44 +0200 Received: from localhost (localhost.localdomain [127.0.0.1]) by relay04ant.iops.be (Postfix) with ESMTP id DE21261B805B; Sun, 25 Jul 2010 13:51:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iops.be; h= content-transfer-encoding:content-type:content-type:mime-version :x-mailer:organization:references:in-reply-to:from:from:subject :subject:message-id:date:date:received:received:received; s= scooby; i=postadmin@iops.be; t=1280058702; bh=u2snYGmhnaAN4pX4cQ eNkMurXDAUa4g3cxtsjC19uDo=; b=1WBaxN9LlW5HpqELCdq/xd5Hn5tD0n5kiS KbP2Dyx2MP/tO2ekwKAWkKWZuYQoK6DlWViqNvZLPGyBM7bQ6BoV7NYB3b+zpCSA a/lGqKm0RIUPAi5/BOLT4Jv9LUg/xjBWTiPEez8ogOm5J7id8OghB1fYWWPYHLH4 UF2QqPEkU= X-Virus-Scanned: amavisd-new at iops.be Received: from relay04ant.iops.be ([127.0.0.1]) by localhost (bdell029.dcn.iops.be [127.0.0.1]) (amavisd-new, port 10026) with LMTP id N2G3HvJYJCYF; Sun, 25 Jul 2010 13:51:42 +0200 (CEST) Received: from poincare (cust-63-199-109-94.dyn.as47377.net [94.109.199.63]) by relay04ant.iops.be (Postfix) with ESMTP id 9A71D61B8087; Sun, 25 Jul 2010 13:51:40 +0200 (CEST) Received: from localhost ([::1]) by poincare with esmtp (Exim 4.72) (envelope-from ) id 1Oczk3-00070g-VF; Sun, 25 Jul 2010 13:51:40 +0200 Date: Sun, 25 Jul 2010 13:51:39 +0200 (CEST) Message-Id: <20100725.135139.32716340832275763.Christophe.Troestler+ocaml@umons.ac.be> To: rixed@happyleptic.org Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Encoding of (constructor * with * tuple) From: Christophe TROESTLER In-Reply-To: <20100725105332.GA4771@happyleptic.org> References: <20100725105332.GA4771@happyleptic.org> X-Face: #2fb%mPx>rRL@4ff~TVgZ"<[:,oL"`TUEGK/[8/qb58~C>jR(x4A+v/n)7BgpEtIph_neoLKJBq0JBY9:}8v|j Organization: University of Mons X-Mailer: Mew version 7.0.50 on Emacs 23.1 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; christophe:01 troestler:01 christophe:01 troestler:01 ocaml:01 0200,:01 ocaml:01 datatype:01 nativeint:01 bigarray:01 nativeint:01 elt:01 bigarray:01 wosize:01 pointer:01 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.