Re:Understanding map, filter, and fold
by jjaredsimpson on Tuesday December 25, 2012 @09:15PM
(#4967877)
It's also illuminating to note that haskell curries function application. This allows us to think of map as a function of one argument.
map :: (a -> b) -> ([a] -> [b])
so instead of thinking that map takes a function and a list and applies that function to the list, we can think that map takes a function and "lifts" that functions argument and result types to the list type.
This thinking leads us directly to Functors and fmap
[a] is a list of a, [b] is a list of b. Map takes a function that takes an a and returns a b, and applies it to every element of [a] in order to produce the [b]. An example usage is
In this case, map takes a function where a is an integer, and b is a boolean, then takes a list of integers and produces a list of booleans.The result is [True,True,False,False]