default class methods in sub-classes

Dylan Alex Simon dylan@dylex.caltech.edu
Wed, 5 Feb 2003 21:16:58 -0800


Apparently I can't do this (in ghc or hugs -- haven't tried others):

class Space a where
  distance :: a -> a -> Int
  subtract :: a -> a -> a

class (Space a) => NormSpace a where
  norm :: a -> Int
  distance a b = norm (subtract a b)

That is, I can't make (or redefine) a default for the superclass method
'distance' in a subclass.  I agree that the Haskell'98 definition doesn't
claim that this should be allowed, but it seems like something that would be
useful.  Are there reasons not to allow this (or that I shouldn't want to do
this at all)?

Apologies if this is well-covered.  I couldn't find any mention of it.

:-Dylan Simon