Reputation: 3061
Can we create Sub Type
of Type Class
in haskell
? Up to how many level sub-typing
of Type Class
can go?
Upvotes: 1
Views: 892
Reputation: 127721
Yes, it is possible to create some kind of subclass in Haskell. It looks basically like this:
class Parent a where
...
class Parent a => Child a where
...
Then any instance of Child
is also required to be an instance of Parent
.
See, for example, Applicative
class.
Also I don't think there is a restriction on 'level' of subclassing since (I guess so) subclassing can be though as sequential union of corresponding instances' class dictionaries which contain their respective implementations of polymorphic functions, and seemingly there are no boundaries for this dictionary growth.
Upvotes: 4