[Haskell-beginners] Re: Beginners Digest, Vol 28, Issue 5

Daniel Fischer daniel.is.fischer at web.de
Sat Oct 2 10:28:12 EDT 2010


On Saturday 02 October 2010 12:14:44, C Gosch wrote:
> I could be wrong, as I am also new to Haskell.

One can also be wrong with lots of experience ;)

> I suppose
> the compiler simply cannot decide which type the lists you want to
> compare are
> (their constituent elements  must be instances of class Eq, but more is
> not known).

Right, that's exactly the problem. In

null' []

the empty list's type is inferred as

[] :: Eq a => [a]

and no further information is available. Under some common circumstances, 
such ambiguous types are resolved by defaulting, cf.
http://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-790004.3.4
but one of the conditions for defaulting is that a numeric class is 
involved. There's no numeric class involved here, so there's no defaulting.

You can make it compile via the ExtendedDefaultRules language extension, 
then ambiguous type variables with an Eq constraint are defaulted to ().

> Adding type signatures will help the compiler (it should say so as well,
> check the
> error messages):
>
> testNull = ([]::[Int]) == ([]::[Int])

Adding one signature is enough, then the type of the other empty list can 
be inferred.

>
> although I don't know why you would want to do such a thing (sorry I did
> not follow the whole thread).

It's about how polymorphism works (type class polymorphism/overloading in 
particular).

>
> Cheers
> Christian



More information about the Beginners mailing list