[Haskell-beginners] ghci: inconsistent return values for succ

Rein Henrichs rein.henrichs at gmail.com
Mon Oct 19 10:13:50 UTC 2015


> That said, I really appreciate Rein's reply and recognize that picking
Double for the extended default rules is "a good choice."

To follow up a bit, the reason that it's a good choice is pragmatic: we
usually prefer to work with such numbers using native floating point math
for speed rather than using rational or computable real or other
representations which are more accurate but many orders of magnitude
slower. If I said 3.5 + 1 in any general purpose language, I would be
surprised if it did anything other than an immediate floating point
calculation, and so it is (by default) in Haskell.

If we want another representation then we must reach for it, but we don't
need to reach very far.

On Sun, Oct 18, 2015 at 10:05 PM Kim-Ee Yeoh <ky3 at atamo.com> wrote:

>
> On Sun, Oct 18, 2015 at 10:57 PM, Frothy Bits <neuralpancake at gmail.com>
> wrote:
>
>> Is the behavior I'm seeing actually related to a bug in parsec?
>
>
> If you're interested in digging deeper, I'd say look at the output, not
> the input end. Almost certainly the machine floating-point double for 3.14
> and (3.14+1.0) are identical across ghc, C, and python.
>
> What's not identical is how different languages choose to display 4.14.
>
> C and python do some display rounding so you don't see the issue. The
> display algorithm in Haskell probably goes for the simple, naive approach.
>
> -- Kim-Ee
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151019/b9eaf491/attachment.html>


More information about the Beginners mailing list