Allow fractional-looking integer literals
Haskell 2010 (2.5, 6.4.1) specifies that there are integer literals and floating literals, which are of types (Num a) => a
and (Fractional a) => a
respectively. This is mostly reasonable, because a Rational
in general can't be converted to an arbitrary Num
instance.
However, there are many specific cases where specifying an integer with compact "floating literal" syntax is reasonable (e.g. 1.2e6
instead of 1200000
). It's possible to do that for any floating literal constant which also happens to be an integer.
Several people have asked for that behavior. Attached is a patch for a proposed extension, NumDecimals
, that implements it.
Note on #2245 (closed): The current fix won't work on converted floating literals, because it involves a special case for FractionalLit
(the right thing to do is probably to generalize that solution, but doing that properly might be complicated). So with the extension enabled, 1e400
would be pretty-printed as an integer (just like 0400 is pretty-printed). Unlike the example in #2245 (closed), though, no information is lost -- floating literals would just be printed in integer form.
Trac metadata
Trac field | Value |
---|---|
Version | 7.6.1 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |