no non-typevariable in instance declarations
José Romildo Malaquias
romildo@urano.iceb.ufop.br
Wed, 15 Nov 2000 03:06:32 -0200
On Tue, Nov 14, 2000 at 02:18:47PM -0800, Jeffrey R. Lewis wrote:
> 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
Thanks, Jeff. I did not know about the -fallow-undecidable-instances
option to GHC. As I am already using some extensions from GHC
(existentialy quantified type variables, multiparameter type
classes, implicit parameters, overlapping instances) I think
I could use undecidable instances too. I hope new versions of
the Haskell language will include them.
Romildo
--
Prof. José Romildo Malaquias <romildo@iceb.ufop.br>
Departamento de Computação
Universidade Federal de Ouro Preto
Brasil