Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004886OCamlCamlp4public2009-10-03 20:312012-09-18 04:29
Reporteryallop 
Assigned Togarrigue 
PrioritynormalSeverityminorReproducibilityalways
StatusfeedbackResolutionopen 
PlatformOSOS Version
Product Version3.11.1 
Target Version4.00.2+devFixed 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)

- 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


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker