[Haskell-cafe] partial inheritance
Donn Cave
donn at avvanta.com
Tue Jul 19 07:47:03 CEST 2011
Quoth "Richard O'Keefe" <ok at cs.otago.ac.nz>,
[ ... re Werner Kuhn "An Image-Schematic Account of Spatial Categories" ... ]
> class BUILDING building where
> <specify the behavior of buildings here, if any>
> class BUILDING house => HOUSE house where
> <specify additional behavior of houses here, if any>
> any instance of HOUSE *will* have in its interface everything that
> any instance of BUILDING will.
But ... for those who might be overly influenced by a superficial
similarity to OOP here ... the idea that the above relationship
makes House a subclass of Building isn't really a natural way to
look at it. It's true that a House instance will also "have
in its interface everything that any instance of Building will",
but only because the programmer is constrained to do that. To
consider the whole outline:
class Building building where
... specify the behavior of buildings here, if any
class Building house => House house where
... specify additional behavior of houses here, if any
data Shed = Shed "shed"
instance Building Shed where
... define Building functions for Shed
instance House Shed where
... define House functions for Shed
The Building => House constraint doesn't add anything, it just
checks that each instance of House also is an instance of Building.
If you omit this constraint, everything will work the same - even
the constraint will still be there, implicitly, albeit not at the
same level. To me, it's somewhat misleading to use words like
"inheritance" and "subclass" for the relationship between Building
and House, unless there's some feature of the system I missed.
Donn
More information about the Haskell-Cafe
mailing list