How to extract the elements of a Haskell list which are on the even position

Viewed 975

Hello dear Community,

I want to get all elements which are on a even position in a list. It's for the implementation of a Dart game.

e.g. [((3,20),(1,19),(2,17)),((3,20),(2,12),(2,19))] -> [((3,20),(1,19),(2,17))]

So far i have tried:

positioneven n [] = []
positioneven n (x:xs) = if even n
                          then (x: positioneven n+1 xs)
                          else     positioneven n+1 xs

But this of course didn't work. I would be very glad if someone can suggest me a better solution.

Thank you ! Nazar

3 Answers
Related