Let us continue with the suggestions for Haskell-2.

To my note

>> Obstacle 3:
>> `newtype' cannot derive all the instances automatically.
>> Thus, in our case,  add (Id 1) (Id 2)  is illegal.
>> ...
>> why Haskell allows the `newtype' derivation only for the standard
>> classes?  Why not support declarations like
>>
>>   newtype N a b =  N (T a b)  deriving(Eq,Ord,AddGroup,Ring)
>>   newtype N a b =  N (T a b)  deriving( all )
>> ?
>> Is there any ambiguity in conversion between (T a b) and  N (T a b)
>> when  N (T a b)  inherits all the instances (T a b) matches in a
>> program?


Simon P.Jones  replies

> That would indeed be possible for newtype; but my guess is
> that if you want 'all' then you ought to be able to get away without
> a newtype at all.  But I might well be wrong about this.
> Anyway, it's not an unreasonable suggestion.

If the language supports the declarations like  
                                          transparentNewtype T a b = a

then, probably, `all' is not needed (though, it needs more thinking).

At least, in Haskell-1.4 it was needed badly. Because to avoid the 
instance overlap between  C a  and  C (D a),  the programmer was often 
forced to introduce  newtype CD a = CD (C (D a)) ...
and needed to derive `all' the old instances before adding specific
ones.


Also i have a feeling Haskell needs some sort of a 

generic isomorphic deriving.
----------------------------
For example, suppose a program  P  declares the instances 
<inst1>...<inst8>  for Pol: 
                         data Polynomial a = Pol [(Mon a)] a [String]

And suppose the  application  needs the extended polynomials - that 
contain, say,  ppComp :: PPComp,  type PPComp = [[Int]] -> Comparison
- to inherit the old instances up to <inst7> and define specially the
instances <inst8>,<inst9> which make the essence of application.

Of course, the user is not to rewrite all P changing the Pol 
declaration. Rather one puts
                             data EPol a = EPol (Polynomial a) PPComp
A natural way to continue is

  data EPol a = EPol (Polynomial a) PPComp
                              isomorhicInstances{ (\ (EPol f _)-> f),
                                                  <inst1>...<inst7> 
                                                }
  instance...=> <inst8> (EPol a)  where  <special way> ...
  instance...=> <inst9> (EPol a)  where  <special way> ...

This means to port <inst1>...<inst7> by compiling each operation
o  as follows:
  cut the PPComp part pp  (add the application of \(EPol f _)->f),
  use the instance for Pol,  put in the end pp back.

Only i wonder whether this is a correct suggestion. 
Something is suspisious in its generality.
And if it is all right, then why not allow any bijective map pairs in 
place of above \(EPol f _)->f  ?


------------------
Sergey Mechveliani
[EMAIL PROTECTED]









Reply via email to