From: Massimiliano Brocchini <brocchini@netseven.it>
To: ocaml <caml-list@inria.fr>
Subject: Camlp4: ctyp antiquotation and polymorphic type question
Date: Wed, 25 Jul 2007 19:52:25 +0200 [thread overview]
Message-ID: <46A78DD9.2060909@netseven.it> (raw)
In-Reply-To: <f8560b80707250838h41983bd7x363ec83f37065a88@mail.gmail.com>
Hi,
I have a type expression stored in a string (obtained by cmigrep) and I
need to attach it to a polymorphic method definition, but I can't obtain
what I expected... I tried two solutions but I miserably failed:
1) with the following code
let t1 = <:ctyp<$anti:quant$>> in
let t2 = <:ctyp<$anti:function_type$>> in
let method_type_expanded = <:ctyp< !$t1$.$t2$ >> in
<:class_str_item< method $x$ : $method_type_expanded$ = $expression$ >>
I get this error message:
[...] While expanding quotation "ctyp" in a position of "expr":
Parse error: illegal begin of quotation of type
I even tried using a list instead of the first ctyp (t1) as mentioned in
the old camlp4 3.07 manual:
let method_type_expanded = <:ctyp< !$list:var_list$.$t2$ >> in
but it doesn't work.
2) I tried building the polymorphic methods type declaration (e.g. 'a
'b. 'a->'b) by concatenation of strings
let method_type = (vars ^ " . " ^ function_type) in
let method_type_expanded = <:ctyp<$anti:method_type$>> in
<:class_str_item< method $x$ : $method_type_expanded$ = $expression$ >>
compiles and works to some extent... it adds the antiquotation in the
translated .ml file which has two problems:
- it is an unparsed string, so no compiler checks on it
- it is surrounded by $ (e.g. method foo : $ 'a. 'a list -> 'a$ = ....)
Could you please explain how to have the antiquotation correctly parsed
by camlp4?
Am I on the wrong path? (I don't feel like writing a parser for type
expressions :( ).
Regards,
Massimiliano Brocchini (camlp4 beginner)
next prev parent reply other threads:[~2007-07-25 17:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-25 15:38 Most recent CVS-branch? Markus Mottl
2007-07-25 17:52 ` Massimiliano Brocchini [this message]
2007-07-26 8:28 ` [Caml-list] " Nicolas Pouillard
2007-07-26 12:46 ` Camlp4: ctyp antiquotation and polymorphic type question Massimiliano Brocchini
2007-07-26 13:23 ` [Caml-list] " Nicolas Pouillard
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=46A78DD9.2060909@netseven.it \
--to=brocchini@netseven.it \
--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