This type error comes up such a lot that I'm copying this message
to the Haskell mailing list.

| The following program does not typecheck under ghc-2.01 unless you
| uncomment the type signature for test.  (ghc-0.29 seems to propagate
| the equality attribute correctly, and doesn't require the annotation.)
| 
|   module Test (test) where
|   -- test :: Eq a => [[a]] -> [a] -> [[a]]
|   test l xs = [ys | ys <- l, ys == map id xs]

The problem here is that there isn't a most general type for test; this is a
shortcoming in the language, not the implementation.  Consider:  map has type

        map :: Monad m => (a->b) -> m a -> m b

Now, you are taking equality over those ys's, that equality over things 
of type (m b).  So the "right" type for test is:

        test :: (Monad m, Eq (m a)) => [m a] -> m a -> [m a]

But alas, Haskell doesn't like the Eq (m a) constraint, so it complains
of a type error.

The solution is presumably to generalise the type system a bit, so that we
recover the principal-type property.

But we want to do the *right* generalisation.  I know Mark Jones is thinking
about this; others are welcome to do so too!

Simon



Reply via email to