Okay, as I wrote in a comment earlier, zipWith (*) (cycle [3,1]) xs
is what you're looking for. But first, a minor nitpick: the head of the list I would call the zeroth element, that's why I have switched the 1 and 3 around :-)
Let's go through a simple example; let xs
be [9,8,7,3,2]
. cycle [3,1]
just repeats its argument over and over so that will be an infinite list starting with [3,1,3,1,3,1,..]. What zipWith f xs ys
does is take the head element of xs
and the head element of ys
and apply f
(which should be a function of two arguments) to those elements - the result of f
then goes onto the front of the result of zipWith
. If one of xs or ys becomes empty, we're done; otherwise we just keep going.
So the first element of the result will be (3 * 9)
, then (1 * 8)
, (3 * 7)
, (1 * 3)
, (3 * 2)
and we're done!
You can have a look at the definition of zipWith
here.
If you really don't want to use the predefined functions, you could define an 'alternating map' taking two functions instead of one, applying the first of these to the head of your argument list and switching the functions around on the recursive call. I'll let you figure out the details there...