[Haskell-beginners] ghci: inconsistent return values for succ
rein.henrichs at gmail.com
Sun Oct 18 18:11:10 UTC 2015
This has nothing to do with Parsec or Decimal. Two things are happening:
First, the type of the literal 3.14 is Fractional a => a. GHCi's extended
default rules  pick Double as the default for Fractional. (This is a
good choice.) Second, the closest number to 4.14 that is reresentable as a
Double is 4.1400000000000001. This is an inherent limitation of the
representation used. This effects every use of floating point numbers in
every programming language, and every programmer should understand this.
See  for more information.
For an exact result, you can provide a different type for your Fractional
literal that is capable of representing the result exactly:
> succ 3.14 :: Rational
207 % 50
> There must be some reason why Float and Double implement the Enum class,
> but I can't understand in what sense (mathematically) are real numbers
You're absolutely right. It is, at best, a kludge and has no mathematical
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners