On 08-Feb-2001, Ketil Malde <[EMAIL PROTECTED]> 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.

Consider

        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 <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.

_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to