|Anonymous | Login | Signup for a new account||2016-05-02 05:46 CEST|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0005837||OCaml||for Camlp4 use https://github.com/ocaml/camlp4/issues||public||2012-11-28 01:41||2015-01-13 19:32|
|Target Version||undecided||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 .. ".
|Transferred to https://github.com/ocaml/camlp4/issues/77 [^]|
|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|
|2013-07-11 20:52||doligez||Target Version||=> 4.02.0+dev|
|2013-07-12 18:15||doligez||Target Version||4.02.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 => 4.02.1+dev|
|2014-09-04 00:25||doligez||Target Version||4.02.1+dev => undecided|
|2015-01-13 19:32||doligez||Note Added: 0013078|
|2015-01-13 19:32||doligez||Status||acknowledged => closed|
|2015-01-13 19:32||doligez||Resolution||open => suspended|
|2016-02-08 12:49||doligez||Category||Camlp4 => for Camlp4 use https://github.com/ocaml/camlp4/issues/102 [^]|
|2016-02-08 12:50||doligez||Category||for Camlp4 use https://github.com/ocaml/camlp4/issues/102 [^] => for Camlp4 use https://github.com/ocaml/camlp4/issues [^]|
|Copyright © 2000 - 2011 MantisBT Group|