caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <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
Date: Mon, 23 Feb 2009 19:27:05 +0900 (JST)	[thread overview]
Message-ID: <20090223.192705.191392073.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <168968.6250.qm@web111509.mail.gq1.yahoo.com>

From: Dario Teixeira <darioteixeira@yahoo.com>

> 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


  reply	other threads:[~2009-02-23 10:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-22 20:59 Dario Teixeira
2009-02-23 10:27 ` Jacques Garrigue [this message]
2009-02-23 16:50   ` [Caml-list] " Dario Teixeira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090223.192705.191392073.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@yquem.inria.fr \
    --cc=darioteixeira@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).