Map (higher-order function)
The map
is provided as part of the Haskell's base prelude (i.e. "standard library") and is implemented as:
Among other uses, this allows defining element-wise operations for various kinds of collections.
The mathematical basis of maps allow for a number of optimizations. The composition law ensures that both
Since reversing a singly linked list is also tail-recursive, reverse and reverse-map can be composed to perform normal map in a tail-recursive way, though it requires performing two passes over the list.