[Haskell-beginners] Type classes vs Java interfaces

Mateusz Kowalczyk fuuzetsu at fuuzetsu.co.uk
Fri Feb 1 00:36:46 CET 2013


Greetings,

I often wonder how one would explain type classes to someone coming from
an environment such as Java. Whenever I think about type classes, I seem
to think of them as Java interfaces. Bah, even the bottom of [1] states
> Haskell classes are roughly similar to a Java interface. Like an
interface declaration, a Haskell class declaration defines a protocol
for using an object rather than defining an object itself.

Is there more to this `roughly similar' statement? Syntax is an obvious
difference but beyond that, I can't think of anything I can do with a
Haskell type class that I wouldn't be able to do with similar amount of
effort with a Java interface, except for the fact that the interface
would look absolutely disgusting syntax wise.

Any insight appreciated.


[1] - http://www.haskell.org/tutorial/classes.html



More information about the Beginners mailing list