I have a question about Haskell polymorphism.
As I’ve learned, there are two types of polymorphism:
-
Parametric: where you do not specify the input type.
Example:
functionName :: [a] -> a -
Overloading: as imperative programming, i.e. passing different arguments to the same function.
My problem is: how does Haskell handle overloading?
Overloading in Haskell is done using type classes. For example, let’s say you want to overload a function
foothat returns anInt:However, they are more powerful than the overloading mechanisms found in most languages. For example, you can overload on the return type:
For more examples, have a look at the predefined type classes in Haskell.