Multiparameter classes in HUGS and GHC

Dean Herington heringto@cs.unc.edu
Wed, 30 Apr 2003 14:45:52 -0400


Graham Klyne wrote:

> class (Eq k, Show k) => Pair a k v where
>      newPair :: (k,v) -> a k v
>      getPair :: a k v -> (k,v)
>
> type MyPair4 k v = (k,v)
>
> instance Pair (Int,String) Int String where
>      newPair = id
>      getPair = id

The kinds are wrong here.  `Pair` takes as its first argument a type constructor of kind: * -> * -> *.
The following works (with appropriate extensions enabled):

instance Pair (,) Int String where
     newPair = id
     getPair = id

> instance Pair (MyPair4 Int String) Int String where
>      newPair = id
>      getPair = id

Again the kinds are wrong.  However, you can't make a Pair instance out of MyPair4 because the latter is
a `type` rather than `newtype` or `data`.

Hope this helps.
Dean