synonym type not allowed

Stefan Karrmann Stefan.Karrmann@math.uni-karlsruhe.de
Wed, 17 Dec 1997 12:37:14 +0100


Arjan van IJzendoorn wrote:
> 
> Hello Erik,
> 
> >:: MyType :== (Int,Real)
> >
> >instance == MyType
> >where   (==) (i1,r1) (i2,r2)    = i1==i2 && r1==r2
> >        (==) _ _                = False
> >
> >This gives:
> >Error [Tryit.icl,17,==]: MyType type synonym used as instance
> 
> Type synonyms can not be allowed as instances of type classes.
> At least, not as they are now. The problem is that the compiler
> can not determine whether the expression (3, 4.0) is of type (Int, Real)
> or of your MyType.

You may regard instances of type synonyms as an instance of the basic
type, then you don't have the problem that the compiler cannot determine
whether the expression (3, 4.0) is of type (Int, Real) or of your
MyType. You always use the instances of type (Int, Real).


> Two solutions have been adopted by other languages:
> Note that Reals are actually called floats in Haskell and Gofer. But
> we can, of course make a type synonym :-)
> 
> a) Gofer
> ...
> b) Haskell (version 1.3 and up, I believe)
> 
>    The latest versions of Haskell support the "newtype"-construct.
>    I'm not completely sure about the syntax:
> 
>    newtype MyType = (Int, Real)

It should be

     newtype MyType = C (Int,Real) -- instead of C you can use MyType

-- 
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                       /________\ \ \ 
                                             \___________\/