I was reading through the paper A tutorial on the universality and expressiveness of fold, and am stuck on the section about generating tuples. After showing of how the normal d
Given the remark that you can / may need to use the original function inside, the claim as stated in your question seems trivial to me:
rewriteAsFold :: ([a] -> (b, [a])) -> [a] -> (b, [a])
rewriteAsFold g = foldr f v where
f x ~(ys,xs) = (fst (g (x:xs)), x:xs)
v = (fst (g []), [])
EDIT: Added the ~
, after which it seems to work for infinite lists as well.