Sven Panne writes:
> GHC-2.10's "overlapping pattern matches"-warnings are sometimes quite puzzling:
> 
> ------------------------
> module Foo where
> 
> bar "-"      = 1
> bar ('-':xs) = 2
> bar _        = 3
> 
> baz ('-':[]) = 1
> baz ('-':xs) = 2
> baz _        = 3
> ------------------------
> 
> Transcript:
> 
>    panne@liesl:/tmp > ghc -c Foo.hs
>    Foo.hs:3: 
>        Warning: Pattern match(es) are overlapped
>            in the definition of function `bar'
>                `('-' : xs) = ...'
>    ghc: module version changed to 1; reason: no old .hi file
> 
> 
> Why is there a warning for bar but none for baz?
>

Hi,

this relates to Alex' query on pattern matching on strings and how GHC
handles them. String literals aren't in general expanded into list
form pre-checking for overlapped/exhaustive patterns; maybe they
should..

> 
> BTW, what do the "discarding polymorphic case"-warnings mean and
> under what circumstances do they occur? I think this has been asked
> before, but I could not find the answer in my mail folders...

Here's my take on it: The code generator isn't currently capable of
dealing with expressions of the form 

  case (expr::a) of
    x -> ...

where `a' is an abstract type (i.e., data constructors not visible.)

Why? Because there's no way of knowing how `expr' is going to return
its result (in the heap or via registers.) 

--Sigbjorn

Reply via email to