[Haskell-cafe] Re: Why the instance declaration , passing on Hug but failing on GHC 6.2.1?

Daniel Fischer daniel.is.fischer at web.de
Thu May 19 15:28:58 EDT 2005


Am Donnerstag, 19. Mai 2005 10:39 schrieb Stefan Holdermans:
> Wukaichen,
>
> > data People = A | B | C | D | E | F deriving (Show, Eq, Ord, Enum)
> >    data Pair a = Pair a a deriving Eq
> >
> >    instance Show (Pair People) where
> >         show (Pair x y) = "<" ++ show x ++ ", " ++ show y ++ ">"
>
> GHC is right, actually. Haskell 98 requires instance declarations to
> have the form
>
>    instance (...) => C (T a1 ... an)
>
> where a1 are type variables, not type constructors as in your example.
>
> However, you can use the Glasgow extensions to get rid of this
> restrictions. For example by adding
>
>    {-# OPTIONS -fglasgow-exts#-}
>
> to the top of your file.
>
> HTH,
>
> Stefan
>

Alternatively, one might define

instance Show a => Show (Pair a) where ...

By the way, the original code also needs the '-98' option for hugs, so the 
behaviour isn't really different.

Cheers,
Daniel



More information about the Haskell-Cafe mailing list