[Haskell-cafe] Re: Numeric type classes

ajb at spamcop.net ajb at spamcop.net
Tue Sep 12 20:59:30 EDT 2006

G'day all.

Quoting Henning Thielemann <lemming at henning-thielemann.de>:

> It seems we are at a point, where we have to define what is a 'number'.

For backwards compatibility, I'd say a Num is what it is at the

One of the proposals that comes up every so often is to allow the
declaration of a typeclass instance to automatically declare instances
for all superclasses.  So, for example:

    class (Functor m) => Monad m where
        fmap f m = m >>= return . f

    instance Monad Foo where
        return a = {- ... -}
        m >>= k = {- ... -}
        fail s = {- ... -}

This will automatically declare an instance of Functor Foo.

Similarly, a finer-grained collection of numeric typeclasses could
simply make Num a synonym for (Show a, Ord a, Ring a, Signum a).
Declaring an instance for (Num Bar) declares all of the other
instances that don't yet have a declaration.

> More precisely: Can you tell me the difference between numbers and "more
> complex mathematical objects"?

Yes.  A Num is anything which supports the common mathematically-
significant operations which are supported by the basic built-in machine
types such as Int and Double.  It need not _be_ a built-in machine type,
but it must support those operations.

(Yes, some architectures support vector operations.  This doesn't count
as "basic".  No, some architectures don't support Double or Word64
natively.  I don't care.)

Andrew Bromage

More information about the Haskell-Cafe mailing list