4.2 Overloading

Haskell uses typeclasses to methodically allow overloading. A
typeclass describes a set of functions, and any type which provides
those functions can be made an instance of that type. This avoids
the syntactic redundancy of languages like OCaml.

For example, the function

*

is a method of the typeclass

Num

, as we can see from its type:

Prelude> :t (*)(*)::(Num a)=> a -> a -> a

Which can be read as "* is a polymorphic function, taking two types 'a',
and returning a result of the same type, where those types are members
of the class Num".

This means that it will operate on any type in the

Num

class, of which the following types are members:

Double,Float,Int,Integer

. Thus:

Prelude>2.3*5.713.11

or on integers:

Prelude>2*510

The type of the arguments determines which instance of

*

is

used. Haskell also never performs implicit coercions, all coercions must
be explicit. For example, if we try to multiply two different types,

Why bother -- why not allow the system to implicitly coerce types?
Implicit type conversions by the system are the source of innumerable
hard to find bugs in languages that support them, and makes reasoning
about a program harder, since you must apply not just the language's
semantics, but an extra set of coercion rules.

Note that If we leave off the type signatures however, Haskell will
helpfully infer the most general type: