-
Notifications
You must be signed in to change notification settings - Fork 8
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
Argument orders of lens functions should follow some formal convention #73
Comments
I don't think any variable-arity functions should contain singular items in the rest arguments. Something with the signature |
And that's another part of why I chose the version of |
Yeah, that makes sense. |
There's some important different shades of possible plurality that are worth noting:
|
In general, do you want the lens before the target, or the target before the lens? Lens before target makes if feel more prefix-y and consistent with function application, while target before lens makes it feel more postfix-y and consistent with functions like |
I think of lenses as abstractions over certain kinds of functions rather than keys or indices to data structures, and I think positioning them first is more in keeping with that feel. What do you think? |
The view should in general go last (exempting plurality exceptions) since it's not given in both lens-view and lens-set |
Re: lens-target vs. target-lens: But in terms of consistency the postfix-y style seems better to me because it's more consistent with the plural forms with multiple lenses, where they should come last. |
There's also the plural form with multiple targets and a single lens to consider. The other big problem is that although backwards compatibility isn't committed to yet, |
Yes. |
What would a plural form with multiple targets and a singular lens look like? |
|
Yes that's just what I was thinking |
Are those as useful? |
They'd just be shorthands, but that would be the case with many of these plural functions like |
But not really for |
There could also be a version that instead of taking one new view for each target in the set takes a single view and sets each target to the same view. |
lens-set* and lens-transform* are more complex, but both are essentially shorthands for a longer |
|
Yes. Given all this, I personally am in favor of lens-target-view for the function-application feel and the backwards compatibility. What do you think? |
And what about the value of keeping the lens and the view next to each other? |
I'm not certain of the value of that because when not doing any setting or updating there isn't a view anyway. |
What if you were doing this: (lens-transform lens (some-really-complicated-target-expression-that-takes-up-space-and-requires-a-little-bit-of-thought) (lambda (val) ...)) Wait, where is this value going again? |
In that case I would probably advocate for a define or let pulling out the complex expression |
That works, and that's probably what I'd do anyway, but it would be better if it weren't necessary. |
For what it's worth, |
And yeah, |
Last thought - lens-first cooperates better with (define set-first-of-second (curry lens-set (lens-compose first-lens second-lens))) |
But also, target-first cooperates better with curry if you want to map that over a list of lenses, so there's two sides to that as well. |
Yeah. I'm not sure arguments about partial application or which two parameters are next to each other really provide support one way or the other, because either way there's counterexamples for the other case. |
And the "function" argument works both ways too, if you like things like |
That it does. I don't think the reasons for target-first are compelling enough to justify the backwards incompatibility. Therefore, I'm going to mark the following conventions as final, in order of priority:
Any last thoughts? |
Ah yes, last thought - in the case of |
Ok. |
Closing this issue now, as all provided exports currently follow this conventions. This no longer blocks 1.0. |
See #72 for the discussion that prompted this issue
UPDATE
The argument order conventions are, in order of decreasing priority, as follows:
transform
functions should follow the same conventions with their transformer arguments taking the place of view arguments.The text was updated successfully, but these errors were encountered: