-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
Lang: partial
operator
#402
Comments
Do you need the |
@cullophid There's no technical reason why the keyword is necessary. We feel that when reading code in languages that allow partial application, it's not at all obvious that a function is being partially applied. You only really know that a partial application is happening if you know the type of the function being called. We wanted something more explicit in Grain, and the |
I'm curious about this; while I agree that reading through code and coming across a partially-applied function can be a bit of a brain-bender the first time you see it, I do wonder if having a Partial application feels similar to me: if a beginner came across code like
That beginner could reasonably ask questions like, "Wait, doesn't String.split take two arguments? Which string is being split?" That's actually a good question, and beginners should ask it, but I don't think it implies that languages should be more verbose. For example, The following code would still provoke questions, I imagine:
The beginner might now ask, "What does
Anyway, just my two cents. 😄 |
Thanks for the feedback! 😄 In the cases where you're familiar with the functions being partially applied, I completely agree with you. If you're not familiar with the functions, say, in user code rather than standard library functions, it's really hard to tell that partial application is happening. A benefit of the I'm all for helpful errors and good tooling though! OCaml has a form of this, where they warn if you have a statement that doesn't return unit. That works pretty well, but you miss out on the warning if you We really like how explicit I should have a draft PR up pretty soon so we can all play around with it and see how it feels. If we hate it, we can remove the keyword! |
Sounds good. A draft PR with the ability to play with the syntax would be a good idea, and I definitely agree that the "google-ability" factor is higher with a keyword rather than the implicit approach! |
I actually like the idea of a partial keyword, as you can easily have a "education" mode where by hovering the keyword you get a link on your IDE to the documentation. And an interesting thing to think about always requiring the partial keyword, is that it makes clear where all the missing parameters will be collected. let f = List.map(x => add(x, _), _)
/* probably means */
let f = z => List.map(x => y => add(x, y), z)
/* but you likely want want */
let f = y => z => List.map(x => add(x, y), z)
/* by having the explicit partial there is no ambiguity */
let f = partial List.map(x => add(x, _), _)
/* means */
let f = y => z => List.map(x => add(x, y), z)
/* and to achieve the naive transformation */
let f = partial List.map(x => partial add(x, _), _)
/* means */
let f = z => List.map(x => y => add(x, y), z) |
I'd have to dig up the conversation in discord, but I believe @peblair wanted to always have the |
The
partial
operator allows you to partially apply a function.For example, look at this implementation of an add function:
In
let add2 = partial add(2)
,add2
is a function that accepts a single argument and adds two to it.Arguments may also be skipped and provided later:
The text was updated successfully, but these errors were encountered: