Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Named function type returns #67
base: master
Are you sure you want to change the base?
Named function type returns #67
Changes from 4 commits
7009e1b
781d5a4
203d3af
8a92b3a
e792a09
5aba1f8
7edc03b
35b94b2
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IME: the way programmers interact with type systems is generally "I'm going to write code how I want until there are no errors." This is especially true for gradual type systems: they're being applied to code written without static typing in mind (trying to run mypy or Pyre on a legacy codebase can be an exercise in frustration because of this).
If I had to guess: I would expect that someone writes code like:
... and then realizes later there was a mismatch. Or at least the vast majority of folks will do so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what mismatch you mean here. I noticed the example wouldn't typecheck because
maybeMap
should prob returnU?
rather thanU
, but that's not got anything to do with return names.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The signature of
maybeMap
states it takes a functionf
of type(item: T) -> (result: U)
, but when we invoke it, we do so withblah
who's type is(foo: number) -> (bar: string)
. The mismatch is in the names of the params / return types.Yeah that has to do with me making a small mistake 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. Sometimes I do this intentionally, where e.g. a generic
maybeMap
function uses generic naming, but when I define a mapping callback inline, it might use names more descriptive based on local information, e.g.:So I wouldn't think a discrepancy like that is always a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's my point: unless you have named parameters, people don't try to match the naming.
OCaml has named parameters that start with tildes, they're a part of the type of the function:
There's support for punning, so one can write code like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. So I think that starts to drift into somewhat adjacent territory around things like named parameter support (as opposed to today's positional parameters) which is out of scope since that's a much heavier change.
I would think of both argument names and return names as "sensible defaults" which document the type generically, without restricting how they're used downstream - it manifests mostly in LSP features.
It's OK for people to not match the names exactly (though it's certainly curious if they rearrange them, because that's probably a mistake, hence the lints).