Show, Eq not necessary for Num [Was: Revamping the numeric c

Marcin 'Qrczak' Kowalczyk qrczak@knm.org.pl
9 Feb 2001 19:31:08 GMT


Fri, 9 Feb 2001 11:48:33 -0500, Dylan Thurston <dpt@math.harvard.edu> pisze:

> > > class (Show a, Read a, Eq a) => Comfortable a
> > > instance (Show a, Read a, Eq a) => Comfortable a 

> Why isn't it legal?

Because in Haskell 98 instance's head must be of the form of a type
constructor applied to type variables. Here it's a type variable.

> I just tried it, and Hugs accepted it, with or without extensions.

My Hugs does not accept it without extensions.

ghc does not accept it by default. ghc -fglasgow-exts accepts an
instance's head which is a type constructor applied to some other
types than just type variables (e.g. instance Foo [Char]), and
-fallow-undecidable-instances lets it accept the above too.

I forgot that it can make context reduction infinite unless the
compiler does extra checking to prevent this. I guess that making it
legal keeps the type system decidable, only compilers would have to
introduce some extra checks.

Try the following module:

------------------------------------------------------------------------
module Test where

class Foo a where foo :: a
class Bar a where bar :: a
class Baz a where baz :: a

instance Foo a => Bar a where bar = foo
instance Bar a => Baz a where baz = bar
instance Baz a => Foo a where foo = baz

f = foo
------------------------------------------------------------------------

Both hugs -98 and ghc -fglasgow-exts -fallow-undecidable-instances
reach their limits of context reduction steps.

-- 
 __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK