[Haskell] Problem with constructing instances for a class Pair
Bulat Ziganshin
bulatz at HotPOP.com
Fri Dec 23 18:01:40 EST 2005
Hello Frank,
Saturday, December 24, 2005, 12:02:28 AM, you wrote:
F> class P a where
F> outl :: a b c -> b
F> outr :: a b c -> c
F> make :: b -> c -> a b c
reusing my answer to David Roundy :)))
are you seen in Hugs manual chapter about multi-parameter type
classes? they use the following
class Collects e ce | ce -> e where
empty :: ce
insert :: e -> ce -> ce
member :: e -> ce -> Bool
instance Eq e => Collects e [e] where ...
instance Eq e => Collects e (e -> Bool) where ...
instance Collects Char BitSet where ...
instance (Hashable e, Collects a ce)
=> Collects e (Array Int ce) where ...
may be you can solve your problem by using
{-# OPTIONS_GHC -fglasgow-exts #-}
class P b c abc | abc -> b, abc -> b where
outl :: abc -> b
outr :: abc -> c
make :: b -> c -> abc
instance P b c (P1 b c) where
outl (P1 p q) = p
outr (P1 p q) = q
make = P1
instance P b c (P2 b c) where
outl = fst
outr = snd
make = (,)
data P1 p q = P1 p q deriving (Show, Eq, Ord)
type P2 = (,)
instance (P b c abc) => P [b] [c] [abc] where
outl = undefined
outr = undefined
make = zipWith make
although it is a bit too verbose... and have problems with defining
outl/outr
F> Andrew U. Frank
F> Professor, Head of Department
i helped Professor? wow! :)
--
Best regards,
Bulat mailto:bulatz at HotPOP.com
More information about the Haskell
mailing list