* [Caml-list] PPX metaquotation question
@ 2016-05-11 18:30 Jonathan DiLorenzo
2016-05-12 7:10 ` Alain Frisch
0 siblings, 1 reply; 2+ messages in thread
From: Jonathan DiLorenzo @ 2016-05-11 18:30 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 613 bytes --]
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
[-- Attachment #2: Type: text/html, Size: 866 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] PPX metaquotation question
2016-05-11 18:30 [Caml-list] PPX metaquotation question Jonathan DiLorenzo
@ 2016-05-12 7:10 ` Alain Frisch
0 siblings, 0 replies; 2+ messages in thread
From: Alain Frisch @ 2016-05-12 7:10 UTC (permalink / raw)
To: Jonathan DiLorenzo, caml-list
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-05-12 7:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-11 18:30 [Caml-list] PPX metaquotation question Jonathan DiLorenzo
2016-05-12 7:10 ` Alain Frisch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox