Opened 3 years ago

Last modified 7 months ago

#7044 new bug

reject reading rationals with exponent notation

Reported by: maeder Owned by:
Priority: normal Milestone: 7.12.1
Component: Compiler Version: 7.4.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #5692,#7266,#9059 Differential Revisions:

Description

The program

main = print (1E1000000000 :: Rational)

fails in the same way as for doubles currently. This should not happen at compile time! Therefore I suggest to forbid using the e-notation for rationals, it is not legal for integers either.

(An alternative would be to evaluate the rational only at run-time)

Change History (11)

comment:1 Changed 3 years ago by pcapriotti

  • difficulty set to Unknown
  • Resolution set to duplicate
  • Status changed from new to closed

This is essentially the same issue as #5692. Let's keep the discussion on that ticket..

comment:2 Changed 3 years ago by maeder

  • Resolution duplicate deleted
  • Status changed from closed to new

It's not the same issue. "1E1000000000" can be easily converted to the Double "Infinity", whereas this is not possible for rationals. Therefore even

main = print (1E10 :: Rational)

should fail as it does for integers!

comment:3 Changed 3 years ago by maeder

hugs has a pragmatic "solution"

Hugs> 1E309 :: Rational

Program error: arithmetic overflow

comment:4 Changed 3 years ago by igloo

  • Milestone set to 7.8.1

comment:5 Changed 15 months ago by thoughtpolice

  • Milestone changed from 7.8.3 to 7.10.1

Moving to 7.10.1.

comment:6 Changed 8 months ago by thomie

Note that with #7266, since 7.8.1, the example for integers is accepted:

$ ghci -XNumDecimals
...
Prelude> 1e10 :: Int
10000000000

Along the same lines, should (1E10 :: Rational) only be accepted when -XNumDecimals is set?

comment:7 Changed 8 months ago by thomie

comment:8 Changed 8 months ago by dfeuer

What am I missing here? Why shouldn't such a thing be allowed? This particular example *should* just run out of memory. Others should work correctly.

comment:9 follow-up: Changed 8 months ago by thomie

The problem is that ghc runs out of memory at compile time, see #5692.

comment:10 in reply to: ↑ 9 Changed 8 months ago by dfeuer

Replying to thomie:

The problem is that ghc runs out of memory at compile time, see #5692.

That's unfortunate, but I think to be expected. Banning the notation is the wrong fix; it'd make more sense to limit it based on size.

comment:11 Changed 7 months ago by thoughtpolice

  • Milestone changed from 7.10.1 to 7.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

Note: See TracTickets for help on using tickets.