Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004886OCamlCamlp4public2009-10-03 20:312014-08-21 11:24
Reporteryallop 
Assigned Togarrigue 
PrioritynormalSeverityminorReproducibilityalways
StatusfeedbackResolutionopen 
PlatformOSOS Version
Product Version3.11.1 
Target Versionafter-4.02.0Fixed in Version 
Summary0004886: Desugaring of camlp4 quotations of labeled patterns duplicates variables
DescriptionHere's a function that extracts the label from a typed labeled pattern:

  open Camlp4.PreCast

  let extract_label = function
    | <:expr< fun ~ ($lab$:$_$) -> $_$ >> -> lab

Here's what happens when you try to compile it:

  $ ocamlc -I +camlp4 -pp camlp4of -c patt.ml
  File "patt.ml", line 4, characters 11-14:
  Error: Variable lab is bound several times in this matching

This is surprising to the user because 'lab' only appears once in the pattern in the source file.

Here's the camlp4 output, showing that the variable 'lab' has been duplicated:

  $ camlp4of patt.ml
  open Camlp4.PreCast
  
  let extract_label =
    function
    | Ast.ExFun (_,
        (Ast.McArr (_,
           (Ast.PaLab (_, lab,
              (Ast.PaTyc (_, (Ast.PaId (_, (Ast.IdLid (_, lab)))), _)))),
           (Ast.ExNil _), _)))
        -> lab

Here's where I think the duplication occurs in the camlp4 source:

        | "~"; "("; i = a_LIDENT; ":"; t = ctyp; ")" ->
            <:patt< ~ $i$ : ($lid:i$ : $t$) >>

        (camlp4/Camlp4Parsers/Camlp4OCamlParser.ml)
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0008101)
garrigue (manager)
2012-09-18 04:29

I think there is no bug here, but a misunderstanding about label syntax:
    fun ~(lab:typ) -> exp
is an abbreviated syntax equivalent to
    fun ~lab:(lab:typ) -> exp
and they share the same abstract syntax representation.
For this reason, if you want to get the label, you should just write:
   <:expr< fun ~$lab$:$_$ -> $_$ >>
(Not checked)
(0009747)
doligez (administrator)
2013-07-10 19:41

Jacques, your suggestion doesn't work, it gives a syntax error. I think it's because of a bug in camlp4: around line 659 in camlp4/Camlp4Parsers/Camlp4OCamlParser.ml, we have :

    labeled_ipatt:
      [ [ i = a_LABEL; p = patt LEVEL "simple" ->
            <:patt< ~ $i$ : $p$ >>
        | "~"; i = a_LIDENT -> <:patt< ~ $i$ >>
        | "~"; "("; i = a_LIDENT; ")" ->
            <:patt< ~ $i$ >>
        | "~"; "("; i = a_LIDENT; ":"; t = ctyp; ")" ->
            <:patt< ~ $i$ : ($lid:i$ : $t$) >>

As far as I can tell, the first case is missing the ":" token between the label and the pattern. Also, the label is given as a a_LABEL token, not a ~ followed by a a_IDENT, so I don't know how to make this work.

Can any camlp4 specialist confirm this?

- Issue History
Date Modified Username Field Change
2009-10-03 20:31 yallop New Issue
2009-10-03 20:31 yallop Status new => assigned
2009-10-03 20:31 yallop Assigned To => ertai
2012-07-11 13:34 doligez Target Version => 4.01.0+dev
2012-07-12 11:29 doligez Assigned To ertai =>
2012-07-12 11:29 doligez Status assigned => acknowledged
2012-07-31 13:36 doligez Target Version 4.01.0+dev => 4.00.1+dev
2012-09-17 17:37 doligez Target Version 4.00.1+dev => 4.00.2+dev
2012-09-18 04:29 garrigue Note Added: 0008101
2012-09-18 04:29 garrigue Assigned To => garrigue
2012-09-18 04:29 garrigue Status acknowledged => feedback
2013-07-10 19:41 doligez Note Added: 0009747
2013-07-10 19:41 doligez Target Version 4.00.2+dev => 4.01.0+dev
2013-08-12 15:50 doligez Target Version 4.01.0+dev => 4.01.1+dev
2014-05-25 20:20 doligez Target Version 4.01.1+dev => 4.02.0+dev
2014-08-21 11:24 doligez Target Version 4.02.0+dev => after-4.02.0


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker