Ticket #1551 (closed bug: invalid)

Opened 6 years ago

Last modified 6 years ago

Incorrect warning: Pattern match(es) are overlapped

Reported by: Regidor Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.6
Keywords: overlapping patterns Cc:
Operating System: Linux Architecture: x86
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

The following program

main = print $ f ab

a = "foo"
ab = "bar"

f :: String -> Int
f a = 0
f ab = 1

produces

Warning: Pattern match(es) are overlapped
             In the definition of `f': f ab = ...

but the patterns don't overlap, i.e., if a matches, ab does not match, and viceversa.

Change History

Changed 6 years ago by duncan

  • status changed from new to closed
  • resolution set to invalid

This is a misunderstanding of the code. I think you're assuming that the 'a' and 'ab' parameters of the function 'f' are standing for the patterns "foo" and "bar", which is not the case.

These 'a' and 'ab' parameters are local variables, they have no relation to the 'a' and 'ab' values you define at the top level.

So if we change the variable names (which is ok as I say, because they're local names) you can see more clearly that they overlap:

f x = 0
f y = 1

both patterns 'x' and 'y' will match any input value, so the first pattern overlaps the second completely. The second case can never happen. So the warning message is correct.

Does that make sense?

For questions like this you might want to ask on the haskell-cafe mailing list:  http://haskell.org/haskellwiki/Mailing_lists

Other resources for learning Haskell:  http://haskell.org/haskellwiki/Learning_Haskell

(I'm closing the bug as invalid)

Note: See TracTickets for help on using tickets.