Re: what's wrong with instance C a => D a. Reply

1997-08-25 Thread Christian Sievers

I wrote:

   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
   :
   : classC a => D a  where  d :: a -> a
   :
   : instance C a => D a  where  d = 
   :
   :
   :   can be replaced with the legal and simpler declaration
   :
   : class C a => D a  where  d :: a -> a
   :  d = 
   :
   [...]
   You're equivalence is correct ...

Buzzz. No, it's not. It does not actually give any instance of D.
You have to declare all of them seperately, and you would rather want
to just say instance C a => D a but you can't.
It's much like the Textual example.

Christian Sievers





Re: what's wrong with instance C a => D a. Reply

1997-08-22 Thread Christian Sievers

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
:
:classC a => D a  where  d :: a -> a
:
:instance C a => D a  where  d = 
:
:
:   can be replaced with the legal and simpler declaration
:
:class C a => D a  where  d :: a -> a
: d = 
:
:   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





what's wrong with instance C a => D a. Reply

1997-08-22 Thread S.D.Mechveliani

Christian Sievers <[EMAIL PROTECTED]>

writes (I format the text)

> The report says explicit that instance declarations like
>
>instance C (a,a) where ...,
> 
> or for  (Int,a)  or for  [[a]] 
>
> are not allowed. I tried to understand this by thinking these 
> types are too complex, but I had to learn that a type may also
> be too simple, i.e. just writing   
>  instance D a 
> is not allowed either.
> ...



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

  classC a => D a  where  d :: a -> a

  instance C a => D a  where  d = 


can be replaced with the legal and simpler declaration

  class C a => D a  where  d :: a -> a
   d = 

Correct me please, if this is a mistake, I am not much of an 
expert in Haskell (though keep on programming for two years!)


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. 

And, yes, the *overlapping instances* too. 
The developers often say these overlaps conflict with the separate 
compilation. But separate compilation is rather a technical detail. 
Besides, might it occure some way-out ... - ?


-
Sergey Mechveliani   [EMAIL PROTECTED]