2
$\begingroup$

The title of the paper that introduced type classes is "How to make ad-hoc polymorphism less ad hoc".

It seems the type classes approach is being compared to how OOP does ad-hoc polymorphism.

As far as I can tell, the paper never explains how type classes are less ad hoc than OOP techniques like V-tables or prototype chains, or even has any comparison at all of the trade-offs between the two approaches.

What is non-ad-hoc about ad-hoc polymorphism via type classes?

Note: this is a somewhat objective question, as "ad-hoc" is here a technical term. From the paper, "Ad-hoc polymorphism occurs when a function is defined over several different types, acting in a different way for each type."

UPDATE Re object-oriented programming: that is not within the scope of the paper. The paper calls out that type classes are related to OO in section 1 but doesn't compare against OO aside from a short comparison of dictionary-passing and v-tables in section 2. Instead, the paper illustrates the problem it attempts to solve using examples from Miranda and SML.

$\endgroup$
8
  • $\begingroup$ Notice that actual title of the paper ends with “ad hoc” without the hyphen. It should be read as “How to make ad-hoc polymorphism more generic”. $\endgroup$ Commented Aug 11, 2020 at 10:30
  • $\begingroup$ Thanks! What's the difference between "ad-hoc" and "ad hoc"? $\endgroup$
    – Max Heiber
    Commented Aug 11, 2020 at 10:39
  • 1
    $\begingroup$ Former is part of a technical term as you said, latter is a phrase in Latin. $\endgroup$ Commented Aug 11, 2020 at 11:07
  • $\begingroup$ I've updated the hyphenation to reflect this distinction $\endgroup$
    – Max Heiber
    Commented Aug 11, 2020 at 11:14
  • $\begingroup$ I do not understand what is being asked. Did you read the paper? If so, do you have a specific question or can you tell us what was unclear about it? $\endgroup$ Commented Aug 23, 2020 at 13:40

1 Answer 1

2
$\begingroup$

The paper is valuable but does not show how to make ad-hoc polymorphism less ad hoc.

I'll review the terminology and then apply it

Terminology

For the definition of "ad-hoc" polymorphism, the reader is pointed to Strachey's Fundamental Concepts in Programming Languages of 1967. Strachey does not hyphenate "ad hoc" and defines it as follows:

There seem to be two main classes [of polymporhpism], which can be called ad hoc polymorphism and parametric polymorphism ... In ad hoc polymorphism there is no single systematic way of determining the type of the result from the type of the arguments. There may be several rules of limited extent which reduce the number of cases, but these are themselves ad hoc both in scope and content ... Parametric polymorphism is more regular and may be illustrated by an example ...

Wadler's "Ad hoc" is not defined in the "Making" paper, so I assume what Wadler means is a pretheoretic notion of "ad hoc". Merriam-Webster's definition of the adverb form "ad hoc" seems apt: "for the particular end or case at hand without consideration of wider application".

Applying the terminology

"ad-hoc" and "ad hoc" as given in the paper appear to be synonyms. So the claim that the paper shows how to make ad-hoc polymorphism less ad hoc is either trivially false or too vague to engage with. The paper might as well be promising to make cheese less cheesey. It's still a great paper!

Why it matters that ad-hoc polymorphism was not made less ad hoc

If we use the terminology in the paper, it's easy to trick ourselves into thinking we are talking about something when we talk about systematic ad-hoc polymorphism. But "systematic ad-hoc polymorphism" is an oxymoron, at least using the definition given.

This leaves open the following possibilities, even without engaging with object oriented programming:

  • type classes are a distinct mechanism for polymorphism that is not parametric polymorphism
  • OR type classes are "just" parametric polymorphism. This would explain (for example) why a similar effect to type classes can be achieved using implicit parameters ("Type Classes as Objects and Implicits”)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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