3

In Graham Hutton's book "Programming in Haskell", he defines a function to be polymorphic, if its type "contains one or more type variables". He then defines a function to be overloaded, if its type "contains one or more class constraints".

From these definitions, my question is, "can a function be polymorphic and overloaded?".

For example, the function elem in the standard prelude, essentially has a type of Eq a => [a] -> Bool. Can we say that this function is both polymorphic and overloaded?

EDIT:

Graham Hutton said "Given that class constraints can only be used to type variables, my answer would be yes, a function can be called both polymorphic and overloaded. In particular, any overloaded function is by these definitions also polymorphic. However, I can understand why someone may wish to keep a distinction between these two terms. For the purposes of the book I wanted to have clear and simple definitions."

Haskell Wiki page, states that elem is an example of "ad-hoc polymorphism", whilst something like id :: a -> a, is an example of "parametric polymorphism".

0

Yes. Following the definition the answer is trivial. If A => B and C => D, then A⋀C => B⋀D

4

An "overloaded" function has to be polymorphic, because it's impossible to write a class constraint unless the function signature already contains a type variable. Based on this, I wouldn't say that overloaded is a very useful concept in Haskell.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.