Ambiguous types

Koen Claessen
Mon, 21 Jan 2002 10:15:21 +0100 (MET)

(moved reply to haskell-cafe)

Ashley Yakeley wrote:

 | But this gives an error:
 |   emptyList :: (Ord a) => [a]
 |   emptyList = []
 |   isempty :: Bool
 |   isempty = null emptyList

Here is another (very similar) case:

  emptyList :: [a]
  emptyList = []

  showEmptyList :: String
  showEmptyList = show emptyList

Now, you might argue that the type error resulting from this
program is too restrictive, since the empty list can always
be shown as: "[]".

But this is not true for all types, look at the way the
empty *string* is shown.

I.e. changing the type of `emptyList' in this example
changes the behavior of `showEmptyList'. The compiler does
not know what type to choose, and thus gives a type error.


Koen Claessen
phone:+46-31-772 5424
Chalmers University of Technology, Gothenburg, Sweden