| The attached file is accepted by GHC 4.08 and Hugs 98.

Here is what was in the attached file:

   module Foo where

   class A a where
      foo :: a value -> ()

   class A a => B a where
      toList :: a value -> [value]

| However if you remove the declaration of "foo" (and for Hugs,
| the now unnecessary "where"  in the declaration of class A),
| both compilers complain.  It appears that in the absence of
| any information, GHC and Hugs assume that the subject of a
| class declaration takes no type parameters.  So how can I
| declare a trivial class for something which does take a type
| parameter? (Yes, I do have a reason for doing this . . .)

Your problem is with the kind of class A.

In the absence of any information about kinds, Haskell assumes
that the kind * was intended.  Thus a Haskell system sees:

  class A a

and deduces that A contains types.  You want it instead to
contain things of kind (* -> *).  See Section 4.6 of the Haskell
report on Kind inference for more explanation.

What you really want here, I suspect, is a kind annotation on
the class parameter ... class A (a :: * -> *).  Haskell 98 does
not support this.  It would be useful for datatypes too in some
cases.  The dummy "foo" member serves as an indirect kind annotation
in your original code.  Other ways to achieve a similar effect are
to declare an appropriate superclass (such as specifying that
instances of the class are also Functor or Monad instances).

All the best,
Mark


Reply via email to