2 May 18:05 2003

## Re: a nice Pair,, was: Multiparameter classes in HUGS and GHC

Derek Elkins <ddarius <at> hotpop.com>

2003-05-02 16:05:35 GMT

2003-05-02 16:05:35 GMT

On Fri, 2 May 2003 11:24:16 +1000 Lloyd Allison <lloyd <at> mail.csse.monash.edu.au> wrote: > On Wed, Apr 30, 2003 at 07:20:06PM +0100, Graham Klyne wrote: > > I've trying to understand better how to use multiparameter classes, > > and in particular the things that can be declared as instances. > > I've consulted the following: > > ... > > > [[ > > class (Eq k, Show k) => Pair a k v where > > newPair :: (k,v) -> a k v > > getPair :: a k v -> (k,v) > > > newtype MyPair1 k v = P1 (Int,String) > > > instance Pair MyPair1 Int String where > > newPair (x,y) = P1 (x,y) > > getPair (P1 (x,y)) = (x,y) > > ... > > > --The nicest Pair that I've ever managed is not: > > class Pair p a b where -- if we use fst' then b is "loose" and > v.v. > fst' :: p->a -- seems to be :: forall a.(p->a), regardless > class Pair p. snd' :: p->b -- can't seem to get a and b from > the instances. > -- Seems to be a problem overloading both fst and snd in one class(Continue reading)