English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
camlp4: let binding
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-04-05 (11:00)
From: Hugo Ferreira <hmf@i...>
Subject: camlp4: let binding

I would like to use a reserved word and substitute that by a function
call. For example, the following:

let  _ = HEAP in
let h1 = HEAP in

would become

let __heap = new_heap () in
let     h1 = new_heap () in

To do this I attempted (here I am not checking the identifier name):

   binding: [
    [ v = LIDENT ; "=" ; "HEAP" -> <:expr<$lid:v$ = new_heap ()>> ]
] ;

My problem however is how to activate the rule above? I figured I need
something like:

    Pcaml.str_item : LEVEL "top" [
          [ "let"; OPT "rec";
          l = LIST1 binding SEP "and" ; "in" ->
                          <str_item:< declare $list:l$ end>>

But this doesn't even compile. I then concentrated on using Pcaml's
let_binding function and see If I could simply reconstruct the
structured expression but failed. I also tried:

    Pcaml.expr: LEVEL "expr1"  [
     "let"; l = LIST1 Pcaml.let_binding SEP "and" ; "in" -> <:expr<$l$>>

Here I get the error:
This expression has type (MLast.patt * MLast.expr) list
but is here used with type MLast.expr

Now I realize that my problem is (re)constructing the expression of a
let binding. I have been at this since yesterday and cannot find a
solution. Does anyone have an example of how to do this?

Hugo Ferreira.