Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Sum and Product aren't Functors

Sum defined in base 4.7.0.2 doesn't have Functor instance. Why?

For example types defined in semigroups package have Functor, Applicative and Monad on e.g. Min, which behave likeIdentity` - makes sense to me.

like image 481
phadej Avatar asked Feb 21 '15 11:02

phadej


1 Answers

I believe the main reason these are not Functor instances is that you have not yet submitted a code review to make them so. You can file a ticket on Trac, then submit a code review on Phabricator. The preferred Phabricator workflow (using Arcanist), along with other details, can be found here.

While you're doing that, you should probably also make them instances of Applicative, and Monad. You should also add Foldable and Traversable instances for them in Data.Foldable and Data.Traversable, respectively.

If you want me to guess why nobody else did this:

While Sum and Product can hold things of any type, the Monoid instances only make sense for Num instances. The type of fmap thus feels a bit oddly general. This, however, is not really a good reason not to make them Functor instances.

like image 113
dfeuer Avatar answered Sep 27 '22 17:09

dfeuer