From: Alain Frisch <alain.frisch@lexifi.com>
To: Jonathan DiLorenzo <jonathan.dilorenzo@gmail.com>, caml-list@inria.fr
Subject: Re: [Caml-list] PPX metaquotation question
Date: Thu, 12 May 2016 09:10:45 +0200 [thread overview]
Message-ID: <c1ea9500-472a-0600-c96c-b5aad6f7a4f0@lexifi.com> (raw)
In-Reply-To: <CADYFzVbHFNoStN9O3g+wz65+_aUy9GMRruDGHCTG-imwuqU8JQ@mail.gmail.com>
Hi Jonathan,
Extension nodes (i.e. [%...] stuff) are not supported by OCaml's syntax
in the context of names in type declarations, so the metaquotation in
ppx_tools cannot support it.
It would be possible to support something like:
let name = "some_type" in
let typ = [%type: string] in
[%stri type [@meta.name] name = [%t typ] ]
When ppx_metaquot detects a specific attribute on type declarations, it
would interpret the name of the declaration as a "host" variable, not a
static name. It could allow passing an expression that compute the
name and then discard the concrete name:
let typ = [%type: string] in
[%stri type [@meta.name "some_type"] t = [%t typ] ]
The same technique could be used to make other component of the type
declaration "dynamic" (recursive flag, list of type parameters, type
kind, etc).
But I'm not convinced this a very good direction: it makes the
"metaquotation" syntactic DSL more complex. It might just be better to
drop the concrete syntax and use directly Ast_helper (or an extra
lighter convenience layer) to build Parsetree fragments.
Alain
On 11/05/2016 20:30, Jonathan DiLorenzo wrote:
> Hey all!
>
> I'm trying to construct a type declaration structure item using the
> metaquotation in ppx_tools and I have two variables containing a string
> with the name of the type and a Parsetree.core_type, like so:
>
> let name = "some_type" in
> let typ = [%type: string] in
> [%stri type [%??? name] = [%t typ] ]
>
> Is there a ??? that lets me do this? Am I going about it all wrong
> somehow? Or do I need to do something like:
>
> open Ast_helper
>
> let name = "some_type" in
> let typ = [%type: string] in
> let type_decl = Type.mk ~manifest:typ { txt=name ; loc = !default_loc} in
> Str.type_ Recursive [type_decl]
>
> Best,
> Jonathan
prev parent reply other threads:[~2016-05-12 7:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-11 18:30 Jonathan DiLorenzo
2016-05-12 7:10 ` Alain Frisch [this message]
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=c1ea9500-472a-0600-c96c-b5aad6f7a4f0@lexifi.com \
--to=alain.frisch@lexifi.com \
--cc=caml-list@inria.fr \
--cc=jonathan.dilorenzo@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