[GHC] #13124: Template Haskell: Floating point literals that cannot be represented by rationals
GHC
ghc-devs at haskell.org
Wed Jan 18 03:25:56 UTC 2017
#13124: Template Haskell: Floating point literals that cannot be represented by
rationals
-------------------------------------+-------------------------------------
Reporter: lerkok | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Template Haskell | Version: 8.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by lerkok):
@goldfire That is a good point! But if TH aims at being able to produce
constants of floats as a valid splice, then this will be an issue.
Imagine a use case where someone uses template-haskell to "optimize" or
"stabilize" numeric expressions. For instance, something like Herbie:
http://herbie.uwplse.org/. There's already a GHC plugin for that:
https://github.com/mikeizbicki/HerbiePlugin. One can easily imagine doing
a similar transformation via TH, and having access to arbitrary floating
constants would be useful. There would be no easy way to write that in TH
today as all the "magic" constants would have to be converted to
rationals, thus having anomalies.
The other place this came up is in the FloatingHex library:
https://hackage.haskell.org/package/FloatingHex-0.4. Currently this isn't
a big issue there since literals supported are typically only positive
ones, but one can imagine having a similar quasi-quoter that supported
negative literals as well. Unfortunately, you cannot represent numbers
such as "-0.0" (negative-zero!), as there is no way to write that as a
rational number. (Note that negative-zero is a "valid" float, which can be
told apart from the good old positive-zero.)
I wouldn't go as far as saying that this is a huge shortcoming, but I
don't see why TH can't just use a good old double/float there instead of
requiring a Rational? Is there a good reason for requiring a Rational
there?
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13124#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list