I have a problem with a haskell program. I want to do something like this:
main = do
print $ map foo [(1, [(2, 3), (4,5)])]
foo :: (Int, [(Int, Int)]) -> (Int, [(Int, Int)])
foo (a, [(b, c)]) = (a+1, [(b, c)])
Then i get the run-time error:
Non-exhaustive patterns in function Main.foo
How is it possible to make such a action?
I just want to access the parameters which are not in the list.
(a, [(b, c)])does not match(1, [(2, 3), (4, 5)]), because the list in the latter has two elements while your pattern requires there to be only one.If you want to leave the list unchanged, use this pattern instead:
Now
barwill match[(2, 3), (4, 5)]because it is just a binding which will match anything of the correct type.