Ambiguous types
Ashley Yakeley
ashley@semantic.org
Mon, 21 Jan 2002 01:59:00 -0800
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