Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created December 16, 2016 10:00
Show Gist options
  • Save tonymorris/0c78e5d122bfb98d5eff15d456bb88a5 to your computer and use it in GitHub Desktop.
Save tonymorris/0c78e5d122bfb98d5eff15d456bb88a5 to your computer and use it in GitHub Desktop.
map :: (a -> b) -> f a -> f b

for example for lists []

map :: (a -> b) -> [a] -> [b]

and for Maybe

map :: (a -> b) -> Maybe a -> Maybe b

and for ((->) t)

map :: (a -> b) -> ((->) t a) -> ((->) t b)

which is the same (syntax change only) as:

map :: (a -> b) -> (t -> a) -> (t -> b)

There is only one possible function with this type. That is, the type implies the program. It is function composition. Function composition is a specialisation of map.

Note the absence of "length" or even "structure" in this latter case.

The map function, in all instances, does need to preserve two things however.

forall x. map id x == x

forall f g x. map f (map g x) == map (f . g) x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment