[Haskell-cafe] Re: Defaulting to Rational [was: Number overflow]
apfelmus
apfelmus at quantentunnel.de
Thu Jul 12 05:39:58 EDT 2007
Donald Bruce Stewart wrote:
> should Rational, or something similar be used instead,
> given that Doubles and Float are broken for a lot of
> basic things (like Eq and Ord), much as we default
> to Integer already.
>
> The issues raised regarding Rational was that you can unexpectedly
> build up large precision, and performance in general, of course.
Well, non-broken Eq and Ord very much depend on large precision.
In a sense, the instances of Eq and Ord for floating point numbers are
wrong. What about rolling new classes for approximate equality and ordering?
class ApproxEq a where
(≈) :: a -> a -> Bool -- almost equal to
class ApproxOrd a where
<< :: a -> a -> Bool -- really less than
>> :: a -> a -> Bool -- really greater than
together with phantom-epsilon
data Eps10
newtype Floating e = F Double
instance ApproxEq (Floating Eps10) where
x ≈ y = abs (x-y) < 1e-10
Regards,
apfelmus
More information about the Haskell-Cafe
mailing list