Better implementation of Show instance for Data.Scientific

Hi there, Data.Scientific just introduced a new implementation of Show instance to display "integers" without radix point or fractional part and display "real numbers" more nicely. While I do like the new formated output, the implementation seems overkill and scared me, so I commented my thought on github: https://github.com/basvandijk/scientific/commit/9f6cbe9192d88becb7dcf3dbce3b... Now, I post here to ask for people's opinion on this as suggested by Bas van Dijk. Thanks. -- Sincerely, Zejun Wu (watashi)

I think it's strange to build the display mode into the data type Scientific, unless Scientific's primary purpose is for *display* rather than representation. For one thing, it mixes two separate roles into one. For another, it would violate the usual expectations for Eq: there would be x and y such that x == y but show x /= show y I prefer the approach of using a separate function (e.g. 'pretty'), as it gives the user more control in situations where Show's default format does not satisfy the needs. If Aeson is not formatting numbers in the way the user expects, then that's really a problem with Aeson. OTOH, I think it makes sense to automatically drop the '.0' when the number is integral, and that could be built into the Show instance. Of course, there's the question of whether such a change would break other packages...

On Sat, 2 May 2015, Phil Ruffwind wrote:
OTOH, I think it makes sense to automatically drop the '.0' when the number is integral, and that could be built into the Show instance. Of course, there's the question of whether such a change would break other packages...
I think if a program relies on a certain formatting in the result of 'show', it is just a bug. Btw. Show should always show valid Haskell expressions as "deriving Show"-generated implementations do.
participants (3)
-
Henning Thielemann
-
Phil Ruffwind
-
watashi