Not really, you don't want a map , but rather a fold. map allows you to convert each element to a list evenly, so you give it a local transform a -> b and it gives a global transform ( [a] -> [b] ). This is not what you want.
As a quick primer on the folds, there is a whole family of them, which allows us to express the calculations that we create by re-applying the function to the initial value, the next element and list, and then repeating this application with the result as a new initial value. So foldl' (+) 0 [1, 2, 3, 4] will be something like
foldl' (+) 0 [1, 2, 3, 4] ==> foldl' (+) 1 [2, 3, 4] ==> foldl' (+) 3 [3, 4] ==> foldl' (+) 6 [4] ==> foldl' (+) 10 [] ==> -- For empty lists we just return the seed given 10
Can you figure out how to postpone the problem in this structure?
Additional Tips
You want to take a list and calculate the result, which depends on each element of the list, something like
gcdAll :: [Int] -> Int gcdAll l = foldl' step initial l
closer to what you want, where step takes the current gcd of the list you have processed so far, and the next element of the list and returns the next value, and the initial one is the value that starts with (and that returns if l empty Since there is actually no normal value, I would divide it into
gcdAll :: [Int] -> Maybe Int gcdAll [] = Nothing gcdAll (h : rest) = Just $ foldl' step h rest
so that you correctly signal the possibility of failure, after all, that gcd is nothing?
Note that foldl' imported from Data.List .