From: Dario Teixeira <darioteixeira@yahoo.com>
To: caml-list@yquem.inria.fr
Subject: Unusual type declaration and Sexplib
Date: Sun, 22 Feb 2009 12:59:14 -0800 (PST) [thread overview]
Message-ID: <168968.6250.qm@web111509.mail.gq1.yahoo.com> (raw)
Hi,
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.
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
So basically the problem is creating the functions with the following signatures:
val sexp_of_t: t -> Sexplib.Sexp.t
val t_of_sexp: Sexplib.Sexp.t -> t
Using as base the automatically created functions whose signatures are as follows:
val sexp_of_foobar_t: ('a -> Sexplib.Sexp.t) -> 'a foobar_t -> Sexplib.Sexp.t
val foobar_t_of_sexp: (Sexplib.Sexp.t -> 'a) -> Sexplib.Sexp.t -> 'a foobar_t
But in practice, I'm having trouble seeing how these later functions can
be used. The problem lies in their recursive definition: how would I
break it? (And yes, I realise that the definition of type t is unusual,
but it's extremely convenient for avoiding a lot of explicit annotations
and coercions [1]).
Thanks for your help!
Best regards,
Dario Teixeira
[1] http://groups.google.com/group/fa.caml/browse_thread/thread/7552095ab859fb5f/9c4a6fd19812fbcc
next reply other threads:[~2009-02-22 20:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-22 20:59 Dario Teixeira [this message]
2009-02-23 10:27 ` [Caml-list] " Jacques Garrigue
2009-02-23 16:50 ` 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=168968.6250.qm@web111509.mail.gq1.yahoo.com \
--to=darioteixeira@yahoo.com \
--cc=caml-list@yquem.inria.fr \
/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