On Thu, 12 Mar 1998, Victor M. Gulias wrote:
| any' p xs = [x | x <- xs, p x] /= []
| all' p xs = [x | x <- xs, p x] == xs
|
| ... the definition of all' does not type check:
|
| a b is not an instance of class "Eq" (hugs 1.4)
Ok.
This error is due to the combination of two reasons.
- Firstly, as you already noted, the "overloading" of the list
comprehension notation. This makes an expression like
[x | x <- xs, p x]
Have the type
Monad l => l a
rather than [a].
- Second, the use of == extends the context of your expression with the
restriction that:
(Monad l, Eq (l a)) => l a
This is currently not allowed in Haskell 1.4. A context may not
restrictions of the form
Foo (a b)
Sadly, this example shows that Haskell 1.4 does not have a principal
typing property. Your function has the type
all' :: Eq a => (a -> Bool) -> [a] -> Bool
As well as:
all' :: Eq a => (a -> Bool) -> F a -> Bool
(for a suitable Monad F). But Haskell is not capable of finding the one
type that contains them all:
all' :: (Monad m, Eq (m a)) => (a -> Bool) -> m a -> Bool
See Peyton Jones, Jones and Meijer '97 (ICFP/Haskell workshop paper) for
more details. I think Simon must have lifted this restriction from the
newest version of GHC. But I am not sure.
Koen.
--
Koen Claessen,
[EMAIL PROTECTED],
http://www.cs.chalmers.se/~koen,
Chalmers University of Technology.