Remove explicit recursion from function with dependent values
haskell, recursion
Solution
Your function is exactly a fold that emits intermediate values. In Haskell this is called a scan. Specifically, scanl1 is equivalent to your `f` except the first element.
f = drop 1 . scanl1 g
Problem
I have the following Haskell function which uses explicit recursion: ``` f :: [a] -> [a] f (a:b:xs) = g a b : f (g a b : xs) where g :: a -> a -> a f (_:[]) = [] f [] = [] ``` Note that the recursive call depends on the value calculated in the step before (by `g`). Is there a way to remove the explicit recursion and if so, how?