You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
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.
Original bug ID: 4886
Reporter: @yallop
Assigned to: @garrigue
Status: closed (set by @damiendoligez on 2015-01-09T18:42:38Z)
Resolution: suspended
Priority: normal
Severity: minor
Version: 3.11.1
Target version: undecided
Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues
Monitored by: @ygrek
Bug description
Here's a function that extracts the label from a typed labeled pattern:
open Camlp4.PreCast
let extract_label = function$lab$ :$$) -> $$ >> -> lab
| <:expr< fun ~ (
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:
The text was updated successfully, but these errors were encountered: