
At 2002-01-21 01:15, Koen Claessen 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: "[]".
Of course not, show doesn't know how to show things of arbitrary type [a]. But null is supposed to work on _any_ list. And just from the type of emptyList, Haskell knows that it is a list of something. -- Ashley Yakeley, Seattle WA

| Of course not, show doesn't know how to show things of | arbitrary type [a]. But null is supposed to work on | _any_ list. And just from the type of emptyList, | Haskell knows that it is a list of something. But from the type you give the function `emptyList': emptyList :: Ord a => [a] we cannot derive that the type of the function `emptyList' does not matter for its result. So, the type checker will complain. If you change the implementation of a function without changing its type, the type checker should still accept the program. /Koen.
participants (2)
-
Ashley Yakeley
-
Koen Claessen