I've tried to transform the following list comprehension:
f xs = [ x+8 | (x,_) <- xs ]
using higher-order functions.
My first solution was:
f' xs = map (\(x,_) -> x+8) xs
After I tried various other approaches, I found out that the following also works:
f' xs = map((+8).fst) xs
Both versions of f'
give the same (correct) output, but I don't understand why (+8).fst
is equal to \(x,_) -> x+8
when using map
on a list of tuples.