Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extensible Haskell Type Classes

I am reading a paper on dependently-typed programming and came across the following quote:

"[...] in contrast to Haskell's type classes, the data type [...] is closed", in the sense that one cannot add new types to the universe without extending the data type.

My newbie question is: in what sense are Haskell type classes open? How are they extensible? Also, what are the type-theoretical consequences of having this property (open vs closed)?

Thank you!

like image 487
AnaK Avatar asked Apr 12 '13 09:04

AnaK


1 Answers

Type classes are open, because you can make arbitrary type an instance of it. When you create type class you specify interface, but not the types which belong to it. Then in any code which includes typeclass definition you can make your type instance of it providing necessary functions from interface using instance TypeClass type of syntax.

like image 89
Adrian Avatar answered Oct 14 '22 15:10

Adrian