3 ms·
Not just essentially. All monads are functors.
by runiq 11y ago
Not just essentially. All monads are functors.
- tamana 11y agoNot in OCaml. It's a different concept.
- moomin 11y agoThere seem to be a hundred language definitions of Functor. Even Haskell's doesn't exactly correspond to the mathematical understanding of the term (if it did, Set would be a functor) C++ is the worst offender, though.
- ch0wn 11y agoHow is Set a functor in a mathmatical sense?
- moomin 11y agoYou can define a function setMap such that if you setMap any function f from a -> b where Set a and Set b are valid types, then setMap f lifts f to a function Set a -> Set b. setMap will also satisfy the functor laws (or law, if you understand the parametricity derivation of the second law, which I don't :) ). Or in other words, setMap id = id. In fact, the mapping is absolutely obvious. Haskell slightly brain damages us by assuming that setMap would have to apply to all a->b functions, which can't be done because a and b need to be Ord. Although apparently it _can_ be done in GHC 8. ish. https://gist.github.com/ekmett/f783ea6af2e041b7b887 https://gist.github.com/ekmett/f783ea6af2e041b7b887