[Haskell-cafe] [] == []

Roman Cheplyaka roma at ro-che.info
Fri May 29 06:28:29 EDT 2009


* Paul Keir <pkeir at dcs.gla.ac.uk> [2009-05-29 10:47:26+0100]
> Hi all,
> 
> GHC is not happy with this:
> 
> f = [] == []
> 
> nor this:
> 
> f' = ([]::(Eq a) => [a]) == ([]::(Eq a) => [a])

Here, there's no guarantee that the answer will be the same independent
of what 'a' you choose. Potentially, you could define different
instances [Int] and [Bool] for Eq, so that [] == [] = True for [Int] but
[] == [] = False for [Bool]. Actually, instance Eq [a] is defined
parametrically on 'a', which implies that equality of lists depends only
on equality of underlying types, therefore [] == [] should be constant,
but compiler doesn't use this information.

If you just want to test a list for emptyness, use 'null'.


-- 
Roman I. Cheplyaka :: http://ro-che.info/
"Don't let school get in the way of your education." - Mark Twain


More information about the Haskell-Cafe mailing list