<p>JHC uses a different approach.  The compiler's intermediate language is a dependently typed lambda-calculus where there is no distinction between types and values.  JHC therefore can perform a case analysis on the type parameter of a function and call the correct overloaded function directly.</p>

<p>The JHC <a href="http://repetae.net/computer/jhc/jhc.shtml">website</a> goes into some depth on the implementation, as well as its advantages over the standard dictionary passing implementation.</p>

CC BY-SA 3.0
2012-11-26T23:00:44.443Z
2012-11-26T23:00:44.443Z
Dominic Mulligan
<p>As far as I know, a Haskell function with type classes constraints is internally compiled to a function with additional arguments that receive dictionaries with the necessary implementations of each particular type class.</p>

<ul>
<li>Are there any other possibilities how compile type classes?</li>
<li>If so, what are their (dis)advantages?</li>
<li>And what compilers use them?</li>
</ul>

CC BY-SA 3.0
2012-09-06T15:34:04.197Z
There's quite a bit of literature on the subject. Maybe start with _Implementing Type Classes_ by J. Peterson, M. Jones. You could also look at _Type Classes as Objects and Implicits_ by Oliveira et al, which talks about this in the context of Scala, but has quite a large section on related work.
Martin Berger
CC BY-SA 3.0
2012-09-06T16:37:54.590Z
I found a link to the paper: [Implementing Type Classes. John Peterson and Mark P. Jones](http://web.cecs.pdx.edu/~mpj/pubs/pldi93.html).
Petr
CC BY-SA 3.0
2012-09-06T20:07:24.070Z
@MartinBerger make this an answer ?
Suresh Venkat
CC BY-SA 3.0
2012-09-06T20:08:07.967Z
The other one can be found [here](http://ropas.snu.ac.kr/~bruno/papers/TypeClasses.pdf).
Martin Berger
CC BY-SA 3.0
2012-09-06T20:12:51.097Z
@Suresh Venkat, I didn't want to make it an answer because I am not sure these two are the best, or even good answers. It's been a while since I looked at implementations of functional languages. Maybe some of the resident FP bods can chime in.
Martin Berger
<pl.programming-languages><functional-programming><compilers><type-systems>
What are possible implementations of Haskell's type classes and what are their (dis)advantages?
Petr
# What are possible implementations of Haskell's type classes and what are their (dis)advantages?

(Asked by: username_0 on 2012-09-06)

As far as I know, a Haskell function with type classes constraints is internally compiled to a function with additional arguments that receive dictionaries with the necessary implementations of each particular type class.

* Are there any other possibilities how compile type classes?
* If so, what are their (dis)advantages?
* And what compilers use them?

**Tags:** pl.programming-languages, functional-programming, compilers, type-systems

> **Comments:**
> **username_1**: There's quite a bit of literature on the subject. Maybe start with _Implementing Type Classes_ by J. Peterson, M. Jones. You could also look at _Type Classes as Objects and Implicits_ by Oliveira et al, which talks about this in the context of Scala, but has quite a large section on related work.  
> **username_0**: I found a link to the paper: [Implementing Type Classes. John Peterson and Mark P. Jones](http://web.cecs.pdx.edu/~mpj/pubs/pldi93.html).  
> **username_2**: @MartinBerger make this an answer ?  
> **username_1**: The other one can be found [here](http://ropas.snu.ac.kr/~bruno/papers/TypeClasses.pdf).  
> **username_1**: @username_2, I didn't want to make it an answer because I am not sure these two are the best, or even good answers. It's been a while since I looked at implementations of functional languages. Maybe some of the resident FP bods can chime in.  

---

## 1 answers

### Answer by username_3 on 2012-11-26. Score: 8

JHC uses a different approach. The compiler's intermediate language is a dependently typed lambda-calculus where there is no distinction between types and values. JHC therefore can perform a case analysis on the type parameter of a function and call the correct overloaded function directly.

The JHC [website](http://repetae.net/computer/jhc/jhc.shtml) goes into some depth on the implementation, as well as its advantages over the standard dictionary passing implementation.


---

