[Haskell-cafe] float show instances

Evan Laforge qdunkan at gmail.com
Thu Nov 7 06:12:50 UTC 2013

Ok, here's a bit of shameless bike-sheddery, so feel free to move on
if you don't have time for that kind of thing.

It seems silly, but this is something that's been bothering me for
something like 5 years now, namely that ghc's float show instance is
very aggressive about resorting to scientific notation for numbers
below 1.  If you get to 0.01 it writes it as 1.0e-2.  Python and ruby,
by comparison, have the cutoff at 1e-5.  But it's only for <1, if you
go higher you have to get all the way up to 1.0e7 before it goes
exponential (python and ruby are even more reluctant: 1e16 and 1e14

This little detail has been a constant low-grade hassle for me because
I don't read scientific notation fluently, and it's hard for me to see
relative magnitudes in a big chunk of floats.  In the past I've
resorted to copy pasting a list into a python prompt or a separate
pretty printer program, and in the present I have my own replacement
for Show that is less aggressive with scientific notation, in addition
to other things.

So I was wondering, was this a considered design choice, or just the
preference of the person who happened to write Show Float and Show
Double way back when?  Are there people who read scientific notation
just as easily as positional (and if so, would they prefer to see 100
as 1e3)?  Is there hope that if I look at it enough maybe someday
it'll be clear to me too?

I'm not actually expecting anyone will say "why didn't we think of
that, let's change it right away", but I'm curious about how it came
about, and whether other people have resorted to as drastic measures
as I have.

As an aside, I've noticed that when I'm debugging, the formatting of
the output is very important.  Surprisingly so.  It's worth it for me
to spend extra time making test and debugging output minimal and
clear, otherwise my brain is already overtaxed trying to understand
the problem, and just can't handle extra load like skipping irrelevant
data, figuring out scientific notation, and even trying to figure out
where the breaks are in un-spaced output.  Maybe a personal quirk.

More information about the Haskell-Cafe mailing list