[Haskell-cafe] 0/0 > 1 == False
Felipe Lessa
felipe.lessa at gmail.com
Wed Jan 16 21:50:45 EST 2008
On Jan 16, 2008 11:30 PM, Derek Elkins <derek.a.elkins at gmail.com> wrote:
> For the love of Pete, floating point numbers are not real numbers. 0/0
> is mathematically defined for floating point numbers to be NaN. If you
> don't want to use IEEE floating point numbers, use a different type as
> was suggested early in this thread.
In fact, you can be happy just by using Rational
Prelude> 0/0 :: Rational
*** Exception: Ratio.%: zero denominator
or creating a newtype
newtype ZeroUndef a = Z {unZ :: a}
instance Eq a => Eq (ZeroUndef a) where
Z a == Z b = a == b
Z a /= Z b = a /= b
instance Show a => Show (ZeroUndef a) where
...
instance Num a => Num (ZeroUndef a) where
...
instance Fractional a => Fractional (ZeroUndef a) where
...
Z a / Z 0 = error "..."
Z a / Z b = Z (a / b)
....
so that ZeroUndef Double, ZeroUndef Float, ZeroUndef Matrix and all
friends do work like you want.
--
Felipe.
More information about the Haskell-Cafe
mailing list