I'm new to Haskell and I want to understand what this syntax means. This is the context of the function:
map' :: (a -> b) -> [a] -> [b]
map' f xs = foldr (\y ys -> (f y):ys) [] xs
It's defining the map function from the prelude in terms of foldr
. I'm confused by what foldr (\y ys -> (f y):ys) [] xs
means. Especially the (\y ys -> (f y): ys)
part.
In my understanding, y
is the first value in the list ys
which is the input and the function f
is being applied to the y
value in the list ys
. I understand these values are taken in the context of pattern matching. Kindly correct me if I'm wrong.