3 ms·
> Why fmap has this law The law is the only law of fmap, which is the "structure preserving law". It means that if you apply a function to each element of the
by kqr 11y ago
> Why fmap has this law
The law is the only law of fmap, which is the "structure preserving law". It means that if you apply a function to each element of the structure, you cannot change the shape of the structure.
This structure preserving property means you can safely apply any function (even ones you don't know what they do) and you can be safe you're not losing information beyond what the function takes away.
> It should possibly be renamed to Container or Mappable to be more in line with what general developers expect.
Mappable would be a truthful name. Container is not a good name because far from all Functors are containers. You can map over a lot of things (I/O actions, functions among others) which are not intuitively "containers", unless you revise your intuition of "container" to mean "mappable". :)
The good thing about calling it for what it is – Functor – is an argument commonly lifted by Edward Kmett: when you're honest about what you're dealing with, you instantly give people access to 80 years of collective knowledge about the thing.