In Haskell, I'm trying to solve a problem where I need to have a function that receives a list of integers and returns the biggest product of two adjacent numbers.
Example: f [5,6,1,3,9] would return 30, that is the product of 5 and 6
The function type would be something like this:
f :: [Int] -> Int
I thought to solve that using recursion to iterate the list getting the 2 head elements with a pattern like this: (x1:x2:xs)
The problem is that I don't know how to keep the product value to compare if the current product is bigger than the last product.
Any ideas?
f [5, 6, 1, 3, 9] == [(5, 6), (6, 1), (1, 3), (3, 9)]?go, that has an additional argument used as intermediate result (your current maximum). The problem: you have to find an initial value. Therefore consider changing the return type of your function and of the intermediate result to anMaybe Int.