Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why were type classes difficult to implement?

On slide 30/78 of this presentation, Simon suggests that implementation of type classes was a "despair" at the beginning. Is anybody aware why that was?

like image 286
Łukasz Lew Avatar asked Mar 07 '12 13:03

Łukasz Lew


People also ask

What are type classes used for?

A typeclass is a sort of interface that defines some behavior. If a type is a part of a typeclass, that means that it supports and implements the behavior the typeclass describes. A lot of people coming from OOP get confused by typeclasses because they think they are like classes in object oriented languages.

What is a type class functional programming?

What is Type Classes: Type classes are one of most important functional programming concept that introduced first in Haskell programming language as a new approach to extend existing classes with new functionality, without using object-oriented inheritance concept, and without changing the original classes source code.


1 Answers

I guess I'm one of the few people who have first hand experience of why it was hard, since I implemented it in hbc when there was no prior art.

So what was clear from the Wadler&Blott paper was that type checking was an extension of Hindley-Milner type checking and that at runtime you should be passing dictionaries around. From that to an actual implementation is a rather big step. A good way to understand the difficulty is to actually implement it starting from just the Wadler-Blott paper.

First, you need to come up with the idea of a type checker that not only checks types but also transforms the program; inserting evidence (dictionaries) while type checking. You also need to figure out how to construct new dictionaries from old ones using the instance declarations as an inference system.

It might all seem obvious in retrospect, but remember that since that time a lot of papers with explanations have been written. Understanding how to do something from a paper is very different from coming up with it in the first place.

Furthermore, you want type classes to be reasonably efficient which leads to its own set of problems.

like image 55
augustss Avatar answered Oct 15 '22 15:10

augustss