
I'm quite convinced the Haskell implementations are correct to complain, I just don't understand it intuitively. Anyway, here's an even simpler example: compiles fine: ordnull :: forall a. (Ord a) => [a] -> Bool ordnull = null ordtrue :: (forall a. (Ord a) => [a]) -> Bool ordtrue = const True gives type error: ordnull :: (forall a. (Ord a) => [a]) -> Bool ordnull = null -- Ashley Yakeley, Seattle WA

Ashley Yakeley wrote:
... gives type error:
ordnull :: (forall a. (Ord a) => [a]) -> Bool ordnull = null
null is able to take a list and look whether its empty. The argument (say l) of ordnull with the given type, however, is a polymorphic list, i.e., for every instance a of Ord, l is a list of a's. The problem is that for some instance A1 of Ord, l might be an empty list, whereas for some other instance A2 of Ord, l might be nonempty. null is not defined to work on such strange objects (how could it? should it try all instances a of Ord?). The question whether such A1, A2 and l as above can be given (which I doubt) is not relevant as far as the type checker cannot know that they do not. -- Janis Voigtlaender http://wwwtcs.inf.tu-dresden.de/~voigt/ mailto:voigt@tcs.inf.tu-dresden.de
participants (2)
-
Ashley Yakeley
-
Janis Voigtlaender