synonym type not allowed

Stefan Karrmann Stefan.Karrmann@math.uni-karlsruhe.de
Wed, 17 Dec 1997 16:29:52 +0100


Arjan van IJzendoorn wrote:
> You're right. Language developers did think of this. However,
> the problems remain. Let me clarify my statement with an example:
> 
> ///////////
> 
> :: Complex :== (Int, Int)
> :: Ratio   :== (Int, Int)
> 
> instance == Complex where
>   (==) (a, b) (c, d) = a == c && b == d
> 
> instance == Ratio where
>   (==) (a, b) (c, d) = a * d == b * c
> 
> Start = (3, 4) == (6, 8)
> 
> ///////////

Now you have two instances for the type (Int, Int)! Of course this
should be illegal. But IMHO type synonyms are not the language
construct to introduce new abstract datatype. It is mainly for humans
to write and read the source code.

> 
> Need I say more?
> Probably not, but I will anyway.
> 
> There is yet another problem. Overlapping instances are not allowed
> in Clean. If you import StdTuple (included in StdEnv),
> an instance for tuple equality is already defined.
> You can not overrule this general equality for
> a two-tuple of Ints.
> 

OK, this reasons disable the example above, but regarding type synonyms
really as synonyms should be possible anyway.

Are instances of other type synonyms possible? E.g.

:: Pred :== Bool -> Bool

instance == Pred where
  f == g = f False == g False && f True == g True


-- 
Stefan Karrmann                                    __      
                                                  / /\     
EMail: Stefan.Karrmann@math.uni-karlsruhe.de     / /  \    
Post: Engelstr. 2, Zimmer 004, 76131 Karlsruhe  / / /\ \   
Tel: +49|0-721-608-3311                        / / /\ \ \  
Post: Ludwig-Wilhelm-Str. 10, 76131 Karlsruhe / /_/__\ \ \ 
priv: +49|0-721-699184                       /________\ \ \ 
                                             \___________\/