[Haskell-cafe] defining mapPairs function

Neil Mitchell ndmitchell at gmail.com
Wed Aug 29 17:06:34 EDT 2007

Hi Alexteslin,

> I just came across with this question on the exam and can not think of
> implementing it.
> mapPair :: (a -> a -> a) -> [a] -> [a]
> such that mapPairs f [x1, x2, x3, x4...] = [f x1 x2, f x3 x4,...]

I would implement this using direct recursion. As a starting point,
the standard definition of map is:

map f [] = []
map f (x:xs) = f x : map f xs

You should be able to start at this and modify it to give the
behaviour you require.

If you want further hints, you might want to try the Haskell IRC
Channel, which is good for these kind of questions.



More information about the Haskell-Cafe mailing list