I am trying to understand the numeric type class hierarchy in Haskell. The basic numeric type is
class Num a where
...
As a side note, according to some of my sources (slides), it should actually be
class Eq a => Num a where
...
but I cannot find this in the Prelude.
Now, I am interested in the Real
type class
class (Num a, Ord a) => Real a where
-- the rational equivalent of its real argument with full precision
toRational :: a -> Rational
I guess that Real
refers to the fact that types that are instances of Real
are not complex. But my understanding of a Real
number from Mathematics is that it can be Rational and Irrational, so there is no equivalent of toRational
for all of them. Of course, irrational numbers can't be used in computers anyways...
Thanks!
Num
requiringEq
is in the Haskell report (the specification), but it's not included in GHC because it's a seriously annoying requirement.Num
is generally regarded as one of the cruftier classes in Haskell: purescript's equivalent is a good example of what a redesign might look like. - oisdk