From: Joel Reymont <joelr1@gmail.com>
To: Nicolas Pouillard <nicolas.pouillard@gmail.com>
Cc: "Caml List" <caml-list@inria.fr>
Subject: Re: Upgrading sexplib-2.7.0 to camlp4 3.10
Date: Tue, 1 May 2007 14:21:45 +0100 [thread overview]
Message-ID: <C642E876-0CAF-47D6-8E29-987D202CDAAB@gmail.com> (raw)
In-Reply-To: <cd67f63a0705010020h60c041eek16451e4c8e103c1a@mail.gmail.com>
Nicolas,
Thank you for your patience!
As per your suggestion, I converted this
| <:ctyp< ( $list:tys$ ) >> -> tupl _loc (List.map aux tys)
into this
| <:ctyp< ( $tup:tys$ ) >> -> tupl _loc (List.map aux
(list_of_ctyp tys []))
where tupl is actually sexp_of_tuple below.
The ultimate goal is to convert ( t1 * ... * tN ) into a Lisp-style
(t1, ..., tN).
My next issue is an error in sex_of_tuple:
This expression has type
(Camlp4.PreCast.Syntax.Ast.patt * Camlp4.PreCast.Syntax.Ast.expr)
list
but is here used with type Camlp4.PreCast.Syntax.Ast.binding list
This points at $list:bindings$. I attached mk_bindings at the end, in
case it's of any use.
How should I rewrite $list:bindings$ here?
I don't understand why $list:bindings$ is assumed to be of type
binding list when bindings itself is [(patt, expr)].
Thanks, Joel
---
(* Conversion of tuples *)
let sexp_of_tuple _loc fps =
let bindings, patts, vars = Gen.mk_bindings _loc fps in
let expr =
<:expr<
let $list:bindings$ in
Sexplib.Sexp.List $Gen.mk_expr_lst _loc vars$
>>
in
let matching =
(
<:patt< ( $list:patts$ ) >>,
None,
expr
)
in
`Match [matching]
(* [mk_rev_bindings _loc fps] takes a list of values of the form
[`Fun fun_expr] and [`Match matching]. [fun_expr] is an
expression
denoting a function, and [matching] is a list of bindings. @return
the tuple [(bindings, patts, var_exprs)], where [bindings] is a
list
of [(pattern, expression)] tuples, [patts] is the list of those
patterns, and [var_exprs] is the expression (variable) associated
with each of those patterns. The resulting lists are reversed. *)
let mk_rev_bindings _loc fps =
let coll (i, bindings, patts, vars) fp =
let name = "v" ^ string_of_int i in
let var_expr = ide _loc name in
let expr =
match fp with
| `Fun fun_expr -> <:expr< $fun_expr$ $var_expr$ >>
| `Match matchings ->
<:expr< match $var_expr$ with [ $list:matchings$ ] >>
in
let patt = idp _loc name in
i - 1, (patt, expr) :: bindings, patt :: patts, var_expr ::
vars in
let n = List.length fps in
let _, bindings, patts, vars =
List.fold_left coll (n, [], [], []) fps in
bindings, patts, vars
(* [mk_bindings _loc fps] same as [mk_rev_bindings] but the resulting
lists are in order. *)
let mk_bindings _loc fps = mk_rev_bindings _loc (List.rev fps)
--
http://wagerlabs.com/
next prev parent reply other threads:[~2007-05-01 13:21 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-30 13:55 Joel Reymont
2007-04-30 14:01 ` Nicolas Pouillard
2007-04-30 14:07 ` Joel Reymont
2007-04-30 14:17 ` Nicolas Pouillard
2007-04-30 14:31 ` Joel Reymont
2007-04-30 14:46 ` Joel Reymont
2007-04-30 15:19 ` Nicolas Pouillard
2007-04-30 15:29 ` Joel Reymont
2007-04-30 15:46 ` Nicolas Pouillard
2007-04-30 19:44 ` Joel Reymont
2007-04-30 21:08 ` Joel Reymont
2007-05-01 7:20 ` Nicolas Pouillard
2007-05-01 13:21 ` Joel Reymont [this message]
2007-05-01 13:35 ` Nicolas Pouillard
2007-05-01 13:54 ` Joel Reymont
2007-05-01 14:16 ` Nicolas Pouillard
2007-05-01 14:31 ` Joel Reymont
2007-05-01 15:49 ` Nicolas Pouillard
2007-05-01 16:14 ` Joel Reymont
2007-05-01 16:27 ` Nicolas Pouillard
2007-05-01 16:35 ` Joel Reymont
2007-05-01 16:39 ` Nicolas Pouillard
2007-05-01 16:50 ` Joel Reymont
2007-05-01 17:13 ` Nicolas Pouillard
2007-05-01 17:04 ` camlp4 3.10: Matching variant types Joel Reymont
2007-05-03 5:58 ` [Caml-list] " Dmitry Bely
2007-05-01 16:05 ` Upgrading sexplib-2.7.0 to camlp4 3.10 Joel Reymont
2007-05-01 16:19 ` Nicolas Pouillard
2007-04-30 21:16 ` Joel Reymont
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=C642E876-0CAF-47D6-8E29-987D202CDAAB@gmail.com \
--to=joelr1@gmail.com \
--cc=caml-list@inria.fr \
--cc=nicolas.pouillard@gmail.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