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=0.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 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 761F9BBAF for ; Mon, 23 Feb 2009 11:32:12 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAGcKokmCNhAB/2dsb2JhbADVTYQPBg X-IronPort-AV: E=Sophos;i="4.38,253,1233529200"; d="scan'208";a="21539181" Received: from kurims.kurims.kyoto-u.ac.jp ([130.54.16.1]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 23 Feb 2009 11:32:11 +0100 Received: from localhost (orion [130.54.16.5]) by kurims.kurims.kyoto-u.ac.jp (8.13.8/8.13.8) with ESMTP id n1NAR4wU006235; Mon, 23 Feb 2009 19:27:04 +0900 (JST) Date: Mon, 23 Feb 2009 19:27:05 +0900 (JST) Message-Id: <20090223.192705.191392073.garrigue@math.nagoya-u.ac.jp> To: darioteixeira@yahoo.com Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Unusual type declaration and Sexplib From: Jacques Garrigue In-Reply-To: <168968.6250.qm@web111509.mail.gq1.yahoo.com> References: <168968.6250.qm@web111509.mail.gq1.yahoo.com> X-Mailer: Mew version 5.2 on Emacs 22.1 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; foobar:01 sexp:01 syntax:01 sig:01 foobar:01 foo:01 val:01 foo:01 val:01 struct:01 sig:01 sexp:01 struct:01 recursively:01 caml-list:01 From: Dario Teixeira > I'm having some trouble serialising via Sexplib a data structure defined > recursively. Consider module M defined below; note how type foobar_t includes > a "with sexp" declaration, telling the Sexplib syntax extension to create > (de)serialisers automatically. However, type t cannot rely on that automatism, > because type declarations with the "as" operator are not fully supported. > Therefore, I need to create the (de)serialisers for this type manually. You program below is exactly equivalent to the following, without as. Or si your real code something different? module M: sig type 'a foobar_t = [ `Foo of int | `Bar of 'a list ] type t = private [< t foobar_t ] val foo: int -> t val bar: t list -> t end = struct type 'a foobar_t = [ `Foo of int | `Bar of 'a list ] type t = t foobar_t let foo x = `Foo x let bar x = `Bar x end Jacques Garrigue > module M: > sig > type 'a foobar_t = > [ `Foo of int > | `Bar of 'a list > ] with sexp > > type t = private [< 'a foobar_t ] as 'a > > val foo: int -> t > val bar: t list -> t > end = > struct > type 'a foobar_t = > [ `Foo of int > | `Bar of 'a list > ] with sexp > > type t = 'a foobar_t as 'a > > let foo x = `Foo x > let bar x = `Bar x > end