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
Original bug ID: 7019 Reporter: jessicah Status: closed (set by @xavierleroy on 2017-02-16T14:14:49Z) Resolution: not a bug Priority: low Severity: minor Platform: Any OS: Any OS Version: Any Version: 4.02.1 Category: typing Monitored by:@gasche@diml@hcarty
Bug description
OCaml accepts two numbers separated by 1 or more + or - signs, which should probably be syntax errors.
When using the pre-processor, the examples do turn into syntax errors.
Steps to reproduce
1 + + 2;;
: int = 3
1 + + + + + + + + + 2;;
: int = 3
1 + + + + +2;;
: int = 3
1 - - 3;;
: int = -2
1 - - - - - - 3;;
: int = - 2
1 - -3;;
: int = 4
1 - - -3;;
: int = -2
1 - - - -3;;
: int = 4
1 - - - - -3;;
: int = -2
The text was updated successfully, but these errors were encountered:
I agree these examples are surprising, but they are valid OCaml syntax. "a - b" means subtraction, but "- a" means "opposite of a". Hence, "a - - b" means "a - (- b)". Likewise, "a + b" means addition, but "+ a" means "the same value as a". (This is a dubious feature that OCaml inherited from other languages such as C, C++ and Java.) Hence "a + + b" means "a + (+ b)", i.e. "a + b". Hope this explains the mystery.
Original bug ID: 7019
Reporter: jessicah
Status: closed (set by @xavierleroy on 2017-02-16T14:14:49Z)
Resolution: not a bug
Priority: low
Severity: minor
Platform: Any
OS: Any
OS Version: Any
Version: 4.02.1
Category: typing
Monitored by: @gasche @diml @hcarty
Bug description
OCaml accepts two numbers separated by 1 or more + or - signs, which should probably be syntax errors.
When using the pre-processor, the examples do turn into syntax errors.
Steps to reproduce
1 + + 2;;
1 + + + + + + + + + 2;;
1 + + + + +2;;
1 - - 3;;
1 - - - - - - 3;;
1 - -3;;
1 - - -3;;
1 - - - -3;;
1 - - - - -3;;
The text was updated successfully, but these errors were encountered: