-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Generalize Base.Fix1
and Base.Fix2
#36181
Comments
I'd primarily love it as a foundation for arbitrary partial evaluation. |
I think it'd be better to have this as an external package. It helps to evolve the API. For example, the current implementation of |
I think having a package is a great idea (I hope someone can help write the macro At the same time I think it's undesirable to have three types |
I think that's a fair argument but workarounds exist. For example, you can export something like const Fix2Like{F, X} = Union{Fix2{F, X}, Bind{F, Tuple{Nothing, Some{X}}}} Also, if you start supporting more complex API like call chains like @rapus95 suggesting, it might be better idea to go with traits-based dispatch rather than doing everything in the method signature (e.g., functions like By the way, I think https://github.com/Tokazama/ChainedFixes.jl is related to your use-case. |
I made a package here: https://github.com/goretkin/Curry.jl @tkf thanks for pointing me to |
I thought |
Personally I think having Base provide generalizations of Fix1 and Fix2 is going to make it easier for the package ecosystem to interact with these mechanisms. As a package author I really don’t want to support |
There is no technical difference if it is in
If there are multiple solutions it means that the API is not consolidated yet. I think it indicates that this is not the right time to put it in |
Sure - I really wasn’t implying you shouldn’t experiment in a package first. :) And yes keyword arguments are important. I’m only saying that the goal should be to eventually have something in |
Yeah, it'd be great if it is eventually integrated into |
I didn't understand the problem with this. The missing keyword argument support means that
In any case, see goretkin/FixArgs.jl#1 for keyword argument support. |
If you document that struct MyStruct
b::Bind{typeof(f), Tuple{Nothing, Some{T}}}
end with the expectation that the field However, adding keyword arguments like |
Well, it doesn’t break that code, it just may make it slower, and we could use a type alias to a new type to work around that too. |
Right. I meant to say that it breaks "the expectation that the field |
Another API to consider is a vararg function. For example, Line 350 in 35c1f87
It'd be nice to cover this in Dispatching to the type returned from this function is very important because the closure is an associative operator. That's why in BangBang.jl Another vararg function that makes sense to curry is |
This comment has been minimized.
This comment has been minimized.
A much more modest extension of (f::Base.Fix1)(ys...) = f.f(f.x, ys...) See #37196 for a use case. Would this create any obvious problems? |
fixed by #54653 |
Fix1
andFix2
are, as far as I can tell, intended to be used internally. I think these types can be extremely useful for some APIs and I think they should be generalized and given elevated status. In addition to being useful in the same places asFix1
andFix2
are used inBase
, by binding some of the arguments, it allows encoding some symbolic manipulation rules in terms of other operations by binding all the arguments.Here's a possible implementation:
e.g.
seems to generate efficient code:
I made a gist trying to demonstrate the benefits I perceive of this proposal. The first example is about replacing
Rational{A, B}
withBind{typeof(/), A, B}
. This probably shouldn't actually be done, and it at least serves as an illustration:https://gist.github.com/goretkin/0d86957dd3279ce9d55993467f872794#file-curry-jl-L47-L58
The second example is about deferring the evaluation of
union(1:3, 5:7)
and carrying a symbolic representation of it to allow more efficient operations downstream.https://gist.github.com/goretkin/0d86957dd3279ce9d55993467f872794#file-curry-jl-L65-L79
I tried to see if this change would wreak havoc in Base, but I was not able to test it out: #36180
Related:
https://www.cplusplus.com/reference/functional/bind/
PR #36094 Document Fix1 and Fix2
https://github.com/c42f/Underscores.jl
The text was updated successfully, but these errors were encountered: