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

Changing ap arguments order for consistency with map and chain, and for better types support #144

Closed
rpominov opened this issue Jul 25, 2016 · 5 comments

Comments

@rpominov
Copy link
Member

rpominov commented Jul 25, 2016

The current order of arguments (if we count this as an argument) in ap is problematic. I see two problems about it.

It's inconsistent with map and chain

map :: (this: A, f: A => B) => MyType<B>
chain :: (this: A, f: A => MyType<B>) => MyType<B>
ap :: (this: MyType<A => B>, x: MyType<A>) => MyType<B>

// sorry about made up types lang, I hope it's clear what I mean here

In map and chain value goes first and function goes second, in ap the other way around.

It's impossible to type with Flow and probably other type systems

... or at least hard, and I didn't figured out how to do it.

// @flow

// With current arguments order we have to use `any`, and therefore loose type info
class MyType<A> {
  ap(other: MyType<any>): MyType<any>
}

// With reversed order it's straightforward
class MyType<A> {
  ap<B>(other: MyType<(x: A) => B>): MyType<B>
}

I understand this is a braking change that will probably break a lot of code. But I just want to open this discussion, and hear what others think. Maybe this is a pain point for many people, and it would be reasonable to make the change.

@SimonRichardson
Copy link
Member

It's been mentioned before, I'll dig out the references, but I'm in favour as well.

@SimonRichardson
Copy link
Member

#50 (comment)

@rpominov
Copy link
Member Author

Ah, right. #50 is specifically about this problem. I remember it was mentioned before, but thought that it was mentioned briefly in an unrelated issue. I guess I created a duplicate then, sorry. I'll close this one.

@SimonRichardson
Copy link
Member

Let's do it, open a PR.

@rpominov
Copy link
Member Author

OK, I'll open one tomorrow.

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