Version française
Home     About     Download     Resources     Contact us    
Browse thread
Most recent CVS-branch?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Massimiliano Brocchini <brocchini@n...>
Subject: Camlp4: ctyp antiquotation and polymorphic type question

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 :( ).

Massimiliano Brocchini (camlp4 beginner)