I have the following function:
ParesImpares:: [Integer] -> ([Integer],[Integer])
I have to get even and odd numbers out of a list:
ParesImpares [3,2,4,5,7]
->([2,4],[3,5,7])
My code so far is as follows:
paresImpares :: [Integer] -> ([Integer],[Integer])
paresImpares [] = ([],[])
paresImpares [x]
| x `mod` 2 == 0 = ([x],[])
| otherwise = ([],[x])
I have defined a base case, but the truth is that I don't know how to proceed. I had in mind something like:
ParesImpares(x:xs) = ParesImpares [x]
But of course, it only evaluates the first element of the list.
There is a more direct solution:
Well I found an answer:
This works perfectly
x
mod2
can be replaced byeven