Overlapping pattern matches
Asked Answered
L

2

6

I have the following code:

test :: String -> Bool
test "g" = True
test "global" = True
test _ = False

When I load it into GHCi (7.0.3), I get:

Warning: Pattern match(es) are overlapped
         In an equation for `test': test "g" = ...

Is this a bug or am I missing something here?

The following hold:

test "" == False
test "g" == True
test "gl" == False
test "global" == True
test "globalx" == False

UPDATE:

I am using {-# LANGUAGE OverloadedStrings #-}.

Luckin answered 24/1, 2012 at 20:28 Comment(0)
I
10

This is GHC bug #5117, arising from the use of the OverloadedStrings extension. It should be fixed in GHC 7.2.

As a workaround, you could turn off OverloadedStrings for the module with {-# LANGUAGE NoOverloadedStrings #-}, or turn off the warning with {-# OPTIONS_GHC -fno-warn-overlapping-patterns #-}. Or just ignore it :)

Infighting answered 24/1, 2012 at 20:33 Comment(0)
J
3

Have you turned on OverloadedStrings? If I remember correctly, that causes 'spurious' overlapping patterns warnings, because in that case it's not clear that e.g. "g" and "global" are mutually exclusive.

Jag answered 24/1, 2012 at 20:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.