Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Haskell's style of polymorphism?

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?

like image 875
Eli Schneider Avatar asked Apr 15 '11 00:04

Eli Schneider


People also ask

What is meant by parametric polymorphism?

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.

What is parametric polymorphism and subtype polymorphism?

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.

What is ad hoc polymorphism in C++?

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.


1 Answers

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:

  • How to make ad-hoc polymorphism less ad hoc, Philip Wadler and Stephen Blott. 16'th Symposium on Principles of Programming Languages, ACM Press, Austin, Texas, January 1989.

For the origin of the distinction between parametric and ad hoc polymorphism, you can dig up Strachey's papers,

  • C. Strachey, Fundamental concepts in programming languages. Lecture notes for the International Summer School in Computer Programming, Copenhagen, August 1967
like image 197
Don Stewart Avatar answered Oct 09 '22 20:10

Don Stewart