Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contravariant Functor? #15

Closed
rjmk opened this issue Aug 21, 2016 · 4 comments
Closed

Contravariant Functor? #15

rjmk opened this issue Aug 21, 2016 · 4 comments

Comments

@rjmk
Copy link
Contributor

rjmk commented Aug 21, 2016

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
Copy link
Member

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
Copy link
Contributor Author

rjmk commented Aug 21, 2016

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
Copy link
Member

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
Copy link
Contributor Author

rjmk commented Aug 21, 2016

Sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants