From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr 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 B64A6BBCA for ; Fri, 29 Feb 2008 19:06:02 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAFnYx0fAXQInh2dsb2JhbACDIY1QAQEBCAoplFuHZA X-IronPort-AV: E=Sophos;i="4.25,427,1199660400"; d="scan'208";a="23215971" Received: from concorde.inria.fr ([192.93.2.39]) by mail4-smtp-sop.national.inria.fr with ESMTP; 29 Feb 2008 19:06:03 +0100 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m1TI5ui2021959 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 29 Feb 2008 19:06:01 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAJPYx0fY7zq5gWdsb2JhbACDIY1QAQEIBQQJChaUXYdk X-IronPort-AV: E=Sophos;i="4.25,427,1199660400"; d="scan'208";a="9758209" Received: from gv-out-0910.google.com ([216.239.58.185]) by mail3-smtp-sop.national.inria.fr with ESMTP; 29 Feb 2008 19:06:01 +0100 Received: by gv-out-0910.google.com with SMTP id i36so1648910gve.28 for ; Fri, 29 Feb 2008 10:06:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=JNu8uEX/4NtCmIaPiDOnHj4hYcV5jc5vvoZRGVuy9vA=; b=rK5MC1i8brvgHByRoNObWUxJUk0ZCc0+BvshqMZTiSVZ06Y9SxsbS+HhA/hRTLQ6AnM/PoTHkyGYbYK1O2zEfSX3ugqG9qrjRwAYsEPnTX3HFkCuu29r/DxsD05CoHcff77JFhZdZOcH56Mw8eMr0uru8iKf3x6FjyVGwR7U6cA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=Up/aExnYYCZCr+5g+MIrBTEfCZfLlnudkX7VOCCTlUjgUWjXAmbp4biCBlOuP3a8EVLraGz+mURH88SPeusNYVcPhfsoSJyB19VlObnMJC5cXiV4WxLd2S7R6Wk/LPbhHgaXG9sItGl25AgTqmRYO0V3Ty4+h6WUGUDYpwUfxIs= Received: by 10.142.226.2 with SMTP id y2mr7220188wfg.64.1204308354576; Fri, 29 Feb 2008 10:05:54 -0800 (PST) Received: by 10.142.102.3 with HTTP; Fri, 29 Feb 2008 10:05:54 -0800 (PST) Message-ID: Date: Fri, 29 Feb 2008 13:05:54 -0500 From: "Markus Mottl" To: "Berke Durak" Subject: Re: [Caml-list] Long-term storage of values Cc: "Gabriel Kerneis" , "Caml-list List" In-Reply-To: <47C7DC1D.9030600@exalead.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <191751.36007.qm@web54607.mail.re2.yahoo.com> <20080229084000.2d3a95fe@tatanka.kerneis.info> <47C7DC1D.9030600@exalead.com> X-Miltered: at concorde with ID 47C84984.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; markus:01 mottl:01 markus:01 mottl:01 berke:01 durak:01 berke:01 durak:01 recursive:01 type-safe:01 serializer:01 mutable:01 marshalling:01 ocaml:01 wrote:01 On Fri, Feb 29, 2008 at 5:19 AM, Berke Durak wrote: > One major drawback of IO is that it does not handle sharing or recursive > structures. And I know of no efficient, type-safe way of handling those, > especially if you don't want the serializer to add extra sharing (for instance > if you have distinct mutable records with the same contents) It shouldn't be too hard to write a macro that generates code for checking whether data marshalled out using the standard marshalling function conforms to a type specification even in the presence of shared or cyclic values. You just need to store a type identifier in an array for every structured value you encounter. Whenever there is a backreference in the marshalled data, you check whether the type denoted by the identifier for the previously seen value unifies with what you expect at the current position. This should be sufficiently efficient. If this type checking succeeds, it should be safe to unmarshal the data using the standard functions. Regards, Markus -- Markus Mottl http://www.ocaml.info markus.mottl@gmail.com