From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 49563BC6B for ; Thu, 26 Jul 2007 15:24:10 +0200 (CEST) Received: from peray.inria.fr (ausone.inria.fr [128.93.8.95]) by discorde.inria.fr (8.13.6/8.13.6) with SMTP id l6QDO9k4008635; Thu, 26 Jul 2007 15:24:09 +0200 Received: by peray.inria.fr (sSMTP sendmail emulation); Thu, _d Jul 2007 15:23:45 +0200 From: "Nicolas Pouillard" Cc: caml-list Subject: Re: [Caml-list] Camlp4: ctyp antiquotation and polymorphic type question To: Massimiliano Brocchini References: <46A897A0.4030700@virgilio.it> In-Reply-To: <46A897A0.4030700@virgilio.it> Date: Thu, 26 Jul 2007 15:23:45 +0200 Message-Id: <1185455462-sup-762@ausone.inria.fr> User-Agent: Sup/0.1 Content-Disposition: inline Content-Type: text/plain; charset=utf-8 X-j-chkmail-Score: MSGID : 46A8A079.001 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 46A8A079.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; camlp:01 ctyp:01 ocaml:01 parser:01 functors:01 quantified:01 camlp:01 ctyp:01 polymorphic:01 polymorphic:01 caml-list:01 expression:02 expression:02 caml:02 caml:02 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 "") 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