caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nicolas Pouillard" <nicolas.pouillard@gmail.com>
To: Massimiliano Brocchini <ebrocchini@virgilio.it>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Camlp4: ctyp antiquotation and polymorphic type question
Date: Thu, 26 Jul 2007 15:23:45 +0200	[thread overview]
Message-ID: <1185455462-sup-762@ausone.inria.fr> (raw)
In-Reply-To: <46A897A0.4030700@virgilio.it>

Excerpts from Massimiliano Brocchini's message of Thu Jul 26 14:46:24 +0200 2007:
> 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:

The antiquotation $anti:...$ is not made to be used by the end-user. If you
have a type expression as a string, then you have to parse it. You can do that
by making an OCaml parser by appling some functors and then be able to parse
it and inject it correctly.

However for quantified variables, I suggest you to switch to a string list and don't try to treat them at once.

(* not tested, but made for camlp4orf *)
open Camlp4.PreCast;;
module Caml =
  Camlp4OCamlParser.Make
    (Camlp4OCamlRevisedParser.Make
      (Camlp4.OCamlInitSyntax.Make(Ast)(Gram)(Quotation)));;

let function_type = "'a -> 'b" in
let quant = ["'a"; "'b"] in
let parse_ctyp = Gram.parse_string Caml.ctyp (Loc.mk "<string>") in
let quant =
  List.fold_right
    (fun t acc -> <:ctyp< $parse_ctyp t$ $acc$ >>) quant <:ctyp<>> in
let function_type = parse_ctyp function_type in
<:class_str_item< method $x$ : ! $list:quant$ . $function_type$ = $expression$ >>

HTH

-- 
Nicolas Pouillard aka Ertai


      reply	other threads:[~2007-07-26 13:24 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 ` Camlp4: ctyp antiquotation and polymorphic type question Massimiliano Brocchini
2007-07-26  8:28 ` [Caml-list] Most recent CVS-branch? Nicolas Pouillard
2007-07-26 12:46 ` Camlp4: ctyp antiquotation and polymorphic type question Massimiliano Brocchini
2007-07-26 13:23   ` Nicolas Pouillard [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=1185455462-sup-762@ausone.inria.fr \
    --to=nicolas.pouillard@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=ebrocchini@virgilio.it \
    /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;
as well as URLs for NNTP newsgroup(s).