Sergey Mechveliani wrote:

:   As to   `instance D a',   
:   it is not a loss. Because `instance D a' is the same as  
:   `class D a' - supplied with the default definition. For example,
:   the illegal declaration pair
:
:            class    C a => D a  where  d :: a -> a
:
:            instance C a => D a  where  d = <definition>
:
:
:   can be replaced with the legal and simpler declaration
:
:            class C a => D a  where  d :: a -> a
:                                     d = <definition>
:
:   Correct me please, if this is a mistake, I am not much of an 
:   expert in Haskell (though keep on programming for two years!)


You may have learned from my other posting that I am also not an
expert :-) -- quite enthusiastic though.
You're equivalence is correct (as much as an illegal decl. can be
equiv. to a legal one), but not general enough for me. I didn't want
the class D to be a subclass of C. Maybe I should give the example
that I have abstracted away from. It's a simple variation of an example
from Mark Jones, given in "Fun. Prog. with overloading and
higher-order polymorphism" in 1st Int. Spring School on
Adv. Fun. Prog. Techniques, LNCS 925. There he defines

> class Dual a  where  dual :: a -> a

(dual is expected to satisfy   dual . dual = id)

> instance Dual Bool  where   dual = not
> instance (Dual a, Dual b) => Dual (a->b)
>                      where dual f = dual . f . dual
> instance (Dual a) => Dual [a]  where  dual = reverse . map dual

and has also

>  instance Dual Int   where   dual = negate

which I tried to replace by the obvious generalisation

?> instance (Num a) => Dual a   where   dual = negate

However, this is not legal in haskell (no problem for gofer).
While this was just experimenting, there might be other examples where
one would like to be able to have instance decls like this. 

The report suggests using 
  class  (Read a, Show a) => Textual a
for which one would have to give explicit instance declarations as
well. If I want to give it for all possible instances, I would want
to write
  instance (Read a, Show a) => Textual a
but I can't.


:   As to         instance ... => C (a  ,a)  where ..., 
:                 ...          => C (Int,a)  where ..., 
:   and such,  
:   they might express a very meaningful mathematical sense, these
:   constructions are highly desirable. 

Actually, these worry me less. If they are meaningful, maybe they
should be given meaningful names. For example, the one you left out,
namely [[a]], if it has some special meaning, which [a] has not, then
there is something really special about it, and it should be called
Matrix a  or so. Though less obvious, I think the same holds for the
other examples. Still, I'd prefer if they were allowed...


Christian Sievers


Reply via email to