Revamping the numeric classes

Fergus Henderson
Thu, 8 Feb 2001 21:41:56 +1100

On 08-Feb-2001, Ketil Malde <> wrote:
> Would it be a terribly grave change to the language to allow leaf
> class instance declarations to include the necessary definitions for
> dependent classes?  E.g.
>         class foo a where
>                 f :: ...
>         class (foo a) => bar a where
>                 b :: ...
>         instance bar T where
>                 f = ...
>                 b = ...

I think that proposal is a good idea.

It means that the user of a class which inherits from some complicated
class hierarchy doesn't need to know (or to write code which depends on)
any of the details of that class hierarchy.  Instead, they can just
give instance declarations for the classes that they want to use,
and provide definitions all of the relevant members.

It means that the developer of a class can split that class into two
or more sub-classes without breaking (source level) backwards compatibility.

One point that needs to be  resolved is the interaction with default methods.


        class foo a where
                f :: ...
		f = ...
                f2 :: ...
		f2 = ...

        class (foo a) => bar a where
                b :: ...
        instance bar T where
		-- no definitions for f or f2
		b = 42

Should this define an instance for `foo T'?
(I think not.)

How about if the instance declaration is changed to

        instance bar T where
		f = 41
		-- no definition for f2
		b = 42

(In that case, I think it should.)

Fergus Henderson <>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <>  |     -- the last words of T. S. Garp.