Instance contexts constraining only type variables?
Wolfgang Jeltsch
wolfgang@jeltsch.net
Thu, 24 Jan 2002 17:39:00 +0100
Wolfgang Lux wrote:
> Wolfgang Jeltsch wrote
>
> > Hello,
> > say I have a type T defined the follwing way:
> > newtype T a b = T (a b)
> > Now I want to make every T a b with a b beeing an instance of Eq also an
> > instance of Eq where (==) just test for equality of the encapsulated values.
> > I
> > try this
> > instance Eq (a b) => Eq (T a b) where
> > (T x) == (T x') = x == x'
> > but it seems that this is not Haskell 98 conformant.
>
> You probably meant a and b being an instance of Eq,
No!
Look at the definition of T. Right to the equals sign there is T (a b) which
implies that a b has kind * and therefore kind (a) = kind (b) -> * if for any
type t kind (t) is the kind of t. So a can never be an instance of Eq because it
doesn't have kind *. Every value of type T encapsulates exactly one value which
is of type a b. I want to test for equality of these values wherefore a b has to
be an instance of Eq.
By the way, why is (* -> *) -> * -> * the infered kind of T and not for instance
((* -> *) -> *) -> (* -> *) -> *?
> so you should write it
> down the same way :-)
>
> instance (Eq a,Eq b) => Eq (T a b) where
> ...
>
> Wolfgang
>
> --
> Wolfgang Lux Phone: +49-251-83-38263
> Institut fuer Wirtschaftinformatik FAX: +49-251-83-38259
> Universitaet Muenster Email: wlux@uni-muenster.de
Wolfgang