The ArrowList class from the hxt package has the following declaration:
class (Arrow a, ArrowPlus a, ArrowZero a, ArrowApply a) => ArrowList a where …
The ArrowPlus class is declared as:
class ArrowZero a => ArrowPlus a where …
The ArrowZero class is declared as:
class Arrow a => ArrowZero a where …
And the ArrowApply class is declared as:
class Arrow a => ArrowApply a where …
Why can’t it just be written as:
class (ArrowPlus a, ArrowApply a) => ArrowList a where …?
No, it’s not necessary to include all the superclasses. If you write
it will work. However, here are two possible reasons for mentioning all the superclasses explicitly.
It might be more readable as you can tell at a glance what all the superclasses are.
It might be slightly more efficient, as listing the superclasses explicitly will result in a direct dictionary lookup at runtime, while for a transitive superclass it will first lookup the dictionary for the superclass and then lookup the class member in that.
For example, take this inheritance chain:
Looking at the generated core for this (with
ghc -c -ddump-simpl), we see that this generates a chain of lookup calls. It first looks up the dictionary forBazinXyzzy, thenBarin that, thenFoo, and finally it can look upfoo.Modifying the definition of
Xyzzyto explicitly mentionFoo:We see that it can now get the
Foodictionary straight from theXyzzyone and look upfooin that.Note that this may be GHC-specific. Tested with version 7.0.2.