From: Matej Kosik <5764c029b688c1c0d24a2e97cd764f@gmail.com>
To: Caml <caml-list@inria.fr>
Subject: [Caml-list] camlp4: a silly question about quoting Ocaml terms
Date: Sat, 02 Nov 2013 19:57:11 +0000 [thread overview]
Message-ID: <52755917.2000808@gmail.com> (raw)
Hello,
According to various sources, Ocaml provides convenient means for generating Ocaml AST.
Yesterday I decided to look into the matter.
Now I am trying to generate a record type.
To certain point, things make sense. This:
<:ctyp<{foo1:bar1; foo2:bar2}>>
is expanded to
Ast.TyRec (_loc,
(Ast.TySem (_loc,
(Ast.TyCol (_loc,
(Ast.TyId (_loc, (Ast.IdLid (_loc, "foo1")))),
(Ast.TyId (_loc, (Ast.IdLid (_loc, "bar1")))))),
(Ast.TyCol (_loc,
(Ast.TyId (_loc, (Ast.IdLid (_loc, "foo2")))),
(Ast.TyId (_loc, (Ast.IdLid (_loc, "bar2")))))))))
By looking at:
http://brion.inria.fr/gallium/index.php/Abstract_Syntax_Tree#Types
there is a line:
<:ctyp< t : t >> ....... Field declaration ........ TyCol of Loc.t and ctyp and ctyp
so it seems that it should also be somehow posible to get a quote for "field declaration", i.e.:
<:ctyp<foo1:bar1>>
However, if I try that, I get an error:
While expanding quotation "ctyp" in a position of "expr":
Parse error: "->" expected after [ctyp level star] (in [ctyp]
I do not quite understand why that quotation was rejected by camlp4.
Of course, it is perfectly possible to write:
Ast.TyCol (_loc,
(Ast.TyId (_loc, (Ast.IdLid (_loc, field_name)))),
field_type
but I am wondering whether there is a more intelligent way to do that
(e.g. <:ctyp<foo1:bar1>> or something like that).
---
As always, thank you in advance for your kind help.
next reply other threads:[~2013-11-02 19:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-02 19:57 Matej Kosik [this message]
2013-11-02 21:27 ` Jeremy Yallop
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=52755917.2000808@gmail.com \
--to=5764c029b688c1c0d24a2e97cd764f@gmail.com \
--cc=caml-list@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