Version française
Home     About     Download     Resources     Contact us    
Browse thread
3.10+beta: Camlp4: AST mapping treats record labels as patterns; should they have type ident instead?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas Pouillard <nicolas.pouillard@g...>
Subject: Re: [Caml-list] 3.10+beta: Camlp4: AST mapping treats record labels as patterns; should they have type ident instead?
On 4/17/07, Aleksey Nogin <nogin@metaprl.org> wrote:
> Currently Camlp4 AST defines the record patterns as
>
>    PaRec of loc and list (patt * patt)
>
> and record expressions as
>
>    ExRec of Loc.t and binding and expr

Why do you mix the old definition of PaRec with the new definition of ExRec.

I recall them:

Before:

  | PaRec of loc and list (patt * patt)

  | ExRec of loc and list (patt * expr) and option expr

Now:

    (* { p } *)
    | PaRec of Loc.t and patt

    (* { b } or { (e) with b } *)
    | ExRec of Loc.t and binding and expr

To fully understand here is a fragment of pattern and binding grammars:

patterns, p ::= ... | { p } | p1 = p2 | p1 ; p2

bindings, b ::= ... | p = e | b ; b

> where the binding can bind arbitrary patterns to expressions. This was
> not a big issue prior to 3.10, but now that 3.10 provides very powerful
> mapping and folding features, this seems a bit problematic. Namely, if I
> define a Camlp4 filter or an AST mapping function that affects patterns,
> the array labels will get affected as well, often in an undesired way.

It's undesired, but there is an easy workaround:

....
method patt p =
  match p with
  | ...
  | <:patt@loc< $p1$ = $p2$ >> -> <:patt@loc< $p1$ = $super#patt p2$ >>
  | ...
....


> Would it be better to have
>    PaRec of loc and list (ident * patt)
> and
>    ExRec of loc and list (ident * expr) and expr
> instead?

There is no more lists in the camlp4 AST, that's a price to pay to
have consistency w.r.t quotations.

For patterns there is something doable:

    | PaEq  of Loc.t and patt and patt (* p = p *)
Can become
    | PaEq  of Loc.t and ident and patt (* i = p *)

Since that node is only used with an ident on his left.

For expressions it's more complex, I won't do it.

Regards,

-- 
Nicolas Pouillard