With Haskell's type classes it almost seems that it enables ad hoc polymorphism, but its functions declarations seem parametric polymorphism. Am I mixing my understanding of different things?
Parametric polymorphism is a programming language technique that enables the generic definition of functions and types, without a great deal of concern for type-based errors. It allows language to be more expressive while writing generic code that applies to various types of data.
1 Parametric polymorphismA polymorphic datatype is one that can contain elements of different types. Several kinds of polymorphism are commonly used in modern languages. • Subtype polymorphism gives a single term many types using the subsumption rule.
Ad hoc polymorphism [Strachey67] in C++ is implemented using overloaded functions. Function overloading allows us to define two or more functions with the same name in the same scope [Wikipedia-4] . Overloaded functions are distinct and potentially heterogeneous implementations over a range of specific types.
Indeed, Haskell supports both (higher rank) parametric polymorphism, and ad hoc (or bounded) polymorphism. Parametric polymorphism in Haskell is supported via its Hindley-Milner/System F type system. Ad hoc polymorphism is supported via type classes.
For the origin of type classes and ad hoc polymorphism, see Wadler's papers:
For the origin of the distinction between parametric and ad hoc polymorphism, you can dig up Strachey's papers,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With