Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006015OCamlOCaml documentationpublic2013-05-16 15:212013-07-12 15:53
Assigned To 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusresolvedResolutionwon't fix 
PlatformOSOS Version
Product Version4.00.1 
Target VersionFixed in Version 
Summary0006015: Negative integer and float literals
DescriptionI never understood this behaviour:

# sin -3.14;;
Error: This expression has type float -> float
but an expression was expected of type int

# pred -1;;
Error: This expression has type int -> int
but an expression was expected of type int

If you follow the grammar production of the docs from expr [1] to integer or float literals the above programs should be interpreted correctly. So what is wrong the lexer [4,5] or the docs ?

Either one should be fixed (and I'd prefer the lexer to be fixed).

[1] [^]
[2] [^]
[3] [^]
[4] [^]
[5] [^]
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
doligez (administrator)
2013-05-17 15:08

The grammar given in the doc is ambiguous and it doesn't decide between your interpretation and the parser's. But if we take x - y to mean x (-y) instead of x - y, we essentially lose the binary - operator.

As far as literals are concerned, it would be possible to implement what you want, but that would break every program that contains (x-1) as an expression without a space between the - and the 1.

So we're not going to change the lexer/parser. If you want to suggest improvements to the doc, they will be welcome, but you should start from the trunk version because it changed a lot since 4.00.
dbuenzli (reporter)
2013-05-17 15:32

Note I'm only talking about literals here. But you are right that it doesn't seem to be reasonable to change the current behaviour. Regarding fixing the doc isn't it just about removing the optional "[-]" from the literals descriptions ?
gasche (developer)
2013-05-17 18:29

Removing "-" from literals would be incorrect, as this is what explains why [-1] is a valid integer list for example. In the current grammar, the ambiguity between minus-as-unary-operator and minus-as-binary-operator is handled through a yacc precedence: the binary operator has precedence over the unary one. This means that in all situations that are *syntactically* ambiguous (it may be that only one choice is well-typed or more generally makes sense), the binary interpretation is chosen.
doligez (administrator)
2013-07-12 15:53

Note that the doc explicitly doesn't try to be fully formal. I'm closing this as "won't fix".

- Issue History
Date Modified Username Field Change
2013-05-16 15:21 dbuenzli New Issue
2013-05-17 15:08 doligez Note Added: 0009291
2013-05-17 15:08 doligez Status new => feedback
2013-05-17 15:08 doligez Category OCaml general => OCaml documentation
2013-05-17 15:32 dbuenzli Note Added: 0009292
2013-05-17 15:32 dbuenzli Status feedback => new
2013-05-17 18:29 gasche Note Added: 0009299
2013-05-17 18:29 gasche Status new => acknowledged
2013-07-12 15:53 doligez Note Added: 0009765
2013-07-12 15:53 doligez Status acknowledged => resolved
2013-07-12 15:53 doligez Resolution open => won't fix

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker