Can a class define a default superclass function?

Ashley Yakeley ashley@semantic.org
Sat, 03 May 2003 00:59:53 -0700


In article <5.1.0.14.2.20030501153714.00b77c40@127.0.0.1>,
 Graham Klyne <gk@ninebynine.org> wrote:

> It appears that it is not possible for a subclass to define a default
> for one of its superclass functions.

Correct. This is a common desire I think especially among people used to 
OOP, but there doesn't seem to be a clean way of doing it. For instance:

 module M where

  class C a where
   foo :: a -> a

  class (C a) => D a where
   foo = id

  instance C Char

 module N where
  import M

  instance D Char


When compiling M, the compiler doesn't know instance D Char, so would 
presumably complain (warning) that foo is not defined in C and give it 
an undefined default.

Perhaps it could work if it were a condition that instances of C and D 
be defined in the same module, and also if missing members in instances 
were errors rather than warnings (a good idea anyway IMO).

-- 
Ashley Yakeley, Seattle WA