## Map in terms of fold

sewe
Sonntagsinformatiker
Beiträge: 295
Registriert: 16. Jan 2009 14:53
Kontaktdaten:

### Map in terms of fold

In todays exercise class the question arose how to implement map in terms of fold and - if I understood the question correctly - to not use explicit function arguments (as in the following):

Code: Alles auswählen

map f l = foldr ((:) . f) [] l
This obviously simplifies to the definition below:

Code: Alles auswählen

map f = foldr ((:) . f) []
Eliminating the very last argument to map, f, is tricky, however:

Code: Alles auswählen

map = flip foldr [] . ((:) .)
So, look up flip and (.) in the Haskell Prelude and try to decipher it.