How can this function be written using foldr?
问题 I have this simple function which returns a list of pairs with the adjacents elements of a list. adjacents :: [a] -> [(a,a)] adjacents (x:y:xs) = [(x,y)] ++ adjacents (y:xs) adjacents (x:xs) = [] I'm having problems trying to write adjacents using foldr . I've done some research but nothing seems to give me a hint. How can it be done? 回答1: Tricky folds like this one can often be solved by having the fold build up a function rather than try to build the result directly. adjacents :: [a] -> [(a