fantasyland / static-land

Specification for common algebraic structures in JavaScript based on Fantasy Land
MIT License
772 stars 41 forks source link

Contravariant Functor? #15

Closed rjmk closed 7 years ago

rjmk commented 8 years ago

Would you be interested in a contravariant functor added to the spec?

It would have a method contramap :: Contravariant f => (a -> b, f b) -> f a. It would become a dependency to profunctor. The laws are pretty much the same as for functor, but with a flip on the functions in composition

Happy to make a PR for you to look over

rpominov commented 8 years ago

Hm interesting! Two main reasons (as I see it) why this can be useful are: 1) a type might have contramap but not map so it cannot implement promap 2) it's annoying to pass x => x to promap when we want to use only contravariant map. Is this how you see it too? Do you have any examples of a type for #1?

rjmk commented 8 years ago

Is this how you see it too?

Yes. I also think it has pedagogical and conceptual advantages -- one can understand the concepts in their parts before their combination.

Do you have any examples of a type for #1?

I believe functions with a fixed codomain are contravariant. e.g.

newtype Predicate a = { getPredicate :: a -> Bool}

rpominov commented 8 years ago

Yea, that a good example! One problem though, I really don't want to go on a road where Static Land starts to diverse from Fantasy Land unless there are really good reasons. Would you consider to open same issue in FL repo?

rjmk commented 8 years ago

Sure!