no non-typevariable in instance declarations

Jeffrey R. Lewis jeff@galconn.com
Tue, 14 Nov 2000 14:18:47 -0800


José Romildo Malaquias wrote:

> On Tue, Nov 14, 2000 at 05:02:30PM +0000, Malcolm Wallace wrote:
> > > class C a where
> > >     ty :: a -> String
> > > instance (Num a) => C a where
> > >     ty _ = "NUM"
> > > instance C Integer where
> > >     ty _ = "Integer"
> >
> > > Why GHC and NHC98 are more restrictive than Hugs?
> >
> > The instances for (Num a=> a) and Integer overlap, and are therefore
> > forbidden by Haskell'98.
>
> But this is not relevant to my question. Removing the instance
> declaration
>
>   instance C Integer where
>       ty _ = "Integer"
>
> from the program (so that there is no instance overlapping now)
> does not help. Both GHC and NHC98 still complains with the
> same diagnostics as before. They are not accepting the
> instance declaration
>
>   instance (Num a) => C a where
>       ty _ = "NUM"
>
> because there is no non-type-variable component in the
> instantiated type "a" above.
>
> Again, why they have this restrictions while Hugs has not?

GHC doesn't have this restriction either, but since it's not Haskell 98,
you don't get it without some effort ;-).  The following combination of
flags will convince GHC to like your program:

    -fallow-overlapping-instances -fallow-undecidable-instances

--Jeff