Hacker News new | ask | show | jobs
by harpocrates 3173 days ago
> It may even be fair to say that Haskell's typeclasses make it more like an object-oriented programming language.

The trick here is defining "object-oriented". In modern object-oriented languages, I usually assume that involves encapsulation of state inside of boxes called objects. In that sense, type classes are quite different.

Methods on objects generally mutate or provide views into the contents of the box, while methods in type classes are just regular functions. Critically, there is no inner mutation or privileged view into data via type classes.

> They have things like properties and multiple inheritance

How do they have properties? Also, they don't have multiple inheritance - a type can only ever have one instance of any given typeclass.

> Even Wadler has a section leading with "Object-oriented programming."

I read Wadler's paragraph on object-oriented programming (bottom of page 3) more as a highlight of the fundamental _difference_ between type classes and object-oriented classes. The only similarity between typeclasses and classes are that they are the mechanisms by which runtime dispatch is achieved.