|Anonymous | Login | Signup for a new account||2013-05-22 11:48 CEST|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0005837||OCaml||Camlp4||public||2012-11-28 01:41||2012-12-03 11:09|
|Target Version||Fixed in Version|
|Summary||0005837: Strange camlp4 rewrite|
|Description||camlp4 rewrites 'let r = ref run () -> ()' in a strange way:|
$ camlp4o -printer Camlp4OCamlPrinter -str 'let r = ref fun () -> ()'
let r = ref
let _ = fun () -> ()
|Steps To Reproduce||$ echo 'let r = ref fun () -> ()' >foo.ml|
$ ocamlc -i foo.ml
File "foo.ml", line 1, characters 12-15:
Error: Syntax error
$ ocamlc -pp camlp4o -i foo.ml
val r : 'a -> 'a ref
|Tags||No tags attached.|
this is syntax ambiguity here
let r = ref ;;
let _ = fun () -> () ;;
let r = ref (fun () -> ()) ;;
since ";;" is optional
Your second alternative is *still* ambiguous. You need extra parentheses to remove the ambiguity:
let r = (ref (fun () -> ()));;
In any case, it seems clear that either camlp4 or ocamlc should change to match the other one.
edited on: 2012-12-03 11:11
OCaml and Camlp4 both reject "ref fun () -> ()" as an expression, despite it being correct according to the hand-wavy context-free grammar of the manual. The problem is that Camlp4 is then clever enough to turn the ambiguity on its head and parse something different, while OCaml's different parsing technology plainly rejects this case.
It's hard to say that Camlp4 is "wrong" in this case, as its resulting parsing is valid as per the grammar rules, and it cannot be faulted for parsing more input than OCaml. However, the parse we really want, if any, would rather be "let r = (ref fun () -> ())", or a rejection of the ambiguity.
I think this is a case where Camlp4 could be changed to mirror OCaml's behavior. However, changing Camlp4's parser is subtle and can have unintented consequences. My own guess it that is a case of "too hard and too risky to fix", and I'm preparing to close the bug as "won't fix" in a medium-term future if nobody acts.
Hongbo or Jérémie, if you disagree with my assessment of the situation or know how to fix this properly, please feel free to take this one!
PS: while a "fun ..." is rejected on the right of an application, it is accepted as a second argument of an infix operator by both OCaml and Camlp4. That is very convenient for monadic-style syntax: "foo >>= fun x -> ..." doesn't need a terminal delimiter, and therefore allows the same style as "let .. in .. ".
|2012-11-28 01:41||elnatan||New Issue|
|2012-11-28 02:30||hongboz||Note Added: 0008542|
|2012-11-28 15:36||elnatan||Note Added: 0008543|
|2012-12-03 11:09||gasche||Note Added: 0008555|
|2012-12-03 11:09||gasche||Status||new => acknowledged|
|2012-12-03 11:11||gasche||Note Edited: 0008555||View Revisions|
|Copyright © 2000 - 2011 MantisBT Group|