I would like to express the following Haskell code, using only functor algebra (i.e. - not relying on any specific container type, such as List
):
ys = zipWith (+) (head xs : repeat 0)
(tail xs ++ [y])
It seems to me that there ought to be a way to do this, relying only on Foldable
(or, maybe, Traversable
), but I can't see it.
I'm wondering:
- Is there a general notion of first and rest for Foldable/Traversable functors?
- Is there an accepted idiomatic way, using only functor algebra, to shift the contents of a Foldable/Traversable functor? (Note that the computation above might be described in English as, "Shift in one value from the right, and add back the value that falls of on the left to the new first value.")