Non-exhaustive patterns in function with tuples HASKELL

Viewed 117
regiuleishon :: (Bool, Integer) -> Integer
regiuleishon (True, _) = 0
reguleishon (False, x) | x >= 0 = 1
                       | otherwise = -1

Why doesn't this code work? The program says:

Exception: pruebas.hs:13:1-26: Non-exhaustive patterns in function regiuleishon

I try to put -> (True, 2) and the response is 0 but if I put (False, 200) :( the exception appears

2 Answers

Because regiuleishon is not reguleishon, so reguleishon (False, x) ... is a new function declaration leading to the code having 2 different functions neither of which have exhaustive patterns.

Name the second pattern correctly:

regiuleishon :: (Bool, Integer) -> Integer
regiuleishon (True, _) = 0
regiuleishon (False, x) | x >= 0 = 1
                        | otherwise = -1

You have a typo: the second line says regiuleishon, but the third line says reguleishon - missing an i after g.

So to the compiler, it looks like you're done defining the function named regiuleishon and moved on to defining a totally different function named reguleishon. The first function only covers the True case, so the pattern match is incomplete. And the second function only covers the False case, so its match is incomplete as well.

Related