From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 31F51BC37 for ; Thu, 29 Oct 2009 10:50:35 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApcCAGMC6UrZSMDdi2dsb2JhbACBT5l3AQEBCgsKBxEFwBiEPQSBYg X-IronPort-AV: E=Sophos;i="4.44,645,1249250400"; d="scan'208";a="35799801" Received: from fmmailgate01.web.de ([217.72.192.221]) by mail2-smtp-roc.national.inria.fr with ESMTP; 29 Oct 2009 10:50:34 +0100 Received: from smtp06.web.de (fmsmtp06.dlan.cinetic.de [172.20.5.172]) by fmmailgate01.web.de (Postfix) with ESMTP id 11B5A132CE083; Thu, 29 Oct 2009 10:50:34 +0100 (CET) Received: from [95.208.117.111] (helo=frosties.localdomain) by smtp06.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #314) id 1N3ReJ-0007wc-00; Thu, 29 Oct 2009 10:50:31 +0100 Received: from mrvn by frosties.localdomain with local (Exim 4.69) (envelope-from ) id 1N3ReJ-0003ZM-90; Thu, 29 Oct 2009 10:50:31 +0100 From: Goswin von Brederlow To: blue storm Cc: Goswin von Brederlow , Sylvain Le Gall , caml-list@inria.fr Subject: Re: [Caml-list] Re: How to read different ints from a Bigarray? References: <87eiond3of.fsf@frosties.localdomain> <87639zd0m9.fsf@frosties.localdomain> <87tyxj5rkv.fsf@frosties.localdomain> <527cf6bc0910281548s53a00ec9s99402f4249b2d411@mail.gmail.com> Date: Thu, 29 Oct 2009 10:50:31 +0100 In-Reply-To: <527cf6bc0910281548s53a00ec9s99402f4249b2d411@mail.gmail.com> (blue storm's message of "Wed, 28 Oct 2009 23:48:06 +0100") Message-ID: <873a52wmu0.fsf@frosties.localdomain> User-Agent: Gnus/5.110006 (No Gnus v0.6) XEmacs/21.4.22 (linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX19Klc4MNpWUPNWW5VUWg52H3wc3Kd0hXDlsNq3C mZcH3VhkClOH+F9DIQsX9XDKZHxx0HPj87c/kMS6Z/IyZN4LVe 2sqX74Dl0= X-Spam: no; 0.00; bigarray:01 buf:01 camlp:01 on-topic:01 foo:01 foo:01 storm:98 28,:98 2009:98 glanced:98 mfg:98 char:01 wrote:01 ints:01 caml-list:01 blue storm writes: > On Wed, Oct 28, 2009 at 6:57 PM, Goswin von Brederlow wrote: >> Maybe ideal would be a format string based interface that calls C with >> a format string and a record of values. Because what I really need is >> to read/write records in an architecture independend way. Something >> like >> >> type t = { x:int; y:char; z:int64 } >> let t_format = "%2u%c%8d" >> >> put_formated buf t_format t >> >> But how to get that type safe? Maybe a camlp4 module that generates >> the format string and type from a single declaration so they always >> match. > > It's possibly off-topic, but you might be interested in Richard > Jones's Bitstring project [1] wich deals with similar issues quite > nicely in my opinion. > > [1] http://code.google.com/p/bitstring/ No, quite on-topic. I glanced at the examples and code and it looks to me though as if this can only parse bitstrings but not create them from a pattern. You have let parse_foo bits = bitmatch bits with | { x : 16 : littleendian; y : 16 : littleendian } -> fun x y -> (x, y) but no let unparse_foo (x, y) = bitmake { x : 16 : littleendian; y : 16 : littleendian } x y Idealy would be something along let pattern = make_pattern { x : 16 : littleendian; y : 16 : littleendian } let parse_foo bits = parse pattern (fun x y -> (x, y)) let unparse_foo (x, y) = unparse pattern x y But I know how to do that with CPS already. I just need the primitives to get/set the basic types. MfG Goswin