-
-
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
replace equalto
and occursin
with curried isequal
, ==
, and in
#26436
Conversation
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.
Makes sense, though I still like @stevengj's proposal to use _ in x
for this. My concern is that there's virtually no limit to the number of functions/operators which could be added a currying version like this (including in packages). And it will always be hard for users to remember which functions implement it and which don't.
For the bikeshedding, CompareTo
sounds a bit weird for in
. Even if more obscure, a general name referring only to currying could be fine. Anyway that's not exposed to most users (and it's not even exported). Maybe that type could even support any number of arguments, by wrapping a tuple to be splat rather than a single value (if there's no performance penalty).
base/operators.jl
Outdated
|
||
(f::OccursIn)(y) = y in f.x | ||
Create a function that compares its argument to `x` using [`==`](@ref); i.e. returns |
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.
While you're at it, "returns a function equivalent to" would be more accurate.
test/arrayops.jl
Outdated
|
||
@testset "findall(::OccursIn, b) for uncomparable element types" begin | ||
@testset "findall(::In, b) for uncomparable element types" begin |
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.
Not a real syntax.
I think it would be a bit odd to implement this style in 1.0 and the underscore style in 1.1. Can we just make up our minds about the latter? |
As a point in favor of the underscore syntax, probably the data people would find it more familiar as at least two packages (Query and JuliaDBMeta) use it already (it was reimplemented via macros): Lazy also reimplemented it with the |
I like the |
32c151a
to
2906bab
Compare
I like the |
The idea would be to share |
Perhaps we could use |
I definitely like that this makes |
I find the proposed methods confusing and would be much more happy with only e.g. (_ == x). One reason that was mentioned yet is the following. We currently have: +(args...) = sum(args)
*(args...) = prod(args) This gives for example +(3) = 3 OTOH from this proposal I would expect +(3) = x -> x + 3 I think implicit currying is confusing in a language that also allows variable number of arguments. |
Triage is on board with trying this. Some observations:
So in short, I think we should limit this convention to binary verb(subject, object) functions and always do specialization on the object. |
Can I suggest a more general type than In particular, how about something like |
That was considered on our call — |
2906bab
to
370fc59
Compare
After sleeping on it, triage has decided to go for this but only do this for strictly binary operators (i.e. only two-arg methods) where the second argument is the object of the verb, which limits the scope creep of this considerably and restricts the convention to cases where it is linguistically intuitive. |
* New function `equalto(x)`, which returns a function that compares its argument to `x` | ||
using `isequal` ([#23812]). | ||
* `isequal`, `==`, and `in` have one argument "curried" forms. For example `isequal(x)` | ||
returns a function that compares its argument to `x` using `isequal` ([#23812]). |
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 PR number should have been updated to 26436 here.
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.
Adjusted in #26480
@mbauman, a problem here is that Can the |
Or we add a deprecated property accessor (either via getproperty or a dedicated function) if we really want to make property access non-breaking? |
The generalized partial application type seems so complicated to me that you might as well encode the AST in the type at that point (as prototyped by @vtjnash). We can just have a rule that |
|
Ok. Can you add them? |
Still waiting on Compat support for this to work on julia 0.6 as well.
Add one argument ``curried'' forms of `isequal`, `==` and `in`. Keep the following definitions to not break Compat on julia v0.6: - Compat.equalto(x) = isequal(x) - Compat.occursin(x) = in(x)
Add one argument ``curried'' forms of `isequal`, `==` and `in`. Keep the following definitions to not break Compat on julia v0.6: - const EqualTo = Fix2{typeof(isequal)} - Compat.equalto(x) = isequal(x) - const OccursIn = Fix2{typeof(in)} - Compat.occursin(x) = in(x)
- Add one argument ``curried'' forms of `isequal`, `==` and `in`. - Keep the following definitions to not break Compat on julia v0.6: - const EqualTo{T} = Fix2{typeof(isequal),T} - equalto(x) = isequal(x) - const OccursIn{T} = Fix2{typeof(in),T} - occursin(x) = in(x)
- Add one argument ``curried'' forms of `isequal`, `==` and `in`. - Keep the following definitions to not break Compat on julia v0.6: - const EqualTo{T} = Fix2{typeof(isequal),T} - equalto(x) = isequal(x) - const OccursIn{T} = Fix2{typeof(in),T} - occursin(x) = in(x)
- Add one argument ``curried'' forms of `isequal`, `==` and `in`. - Keep the following definitions to not break Compat on julia v0.6: - const EqualTo{T} = Fix2{typeof(isequal),T} - equalto(x) = isequal(x) - const OccursIn{T} = Fix2{typeof(in),T} - occursin(x) = in(x)
- Add one argument ``curried'' forms of `isequal`, `==` and `in`. - Keep the following definitions to not break Compat on julia v0.6: - const EqualTo{T} = Fix2{typeof(isequal),T} - equalto(x) = isequal(x) - const OccursIn{T} = Fix2{typeof(in),T} - occursin(x) = in(x)
was there a particular reason why you didn't add |
No, that would be a good one as well. |
Not sure where to write this... but after getting used to |
These were my silly idea, so I'll try to clean it up. I think this is nicer, frees up
occursin
, and easily generalizes to other functions.This is really just currying on the second argument, but it's especially useful for comparisons since e.g.
in(xs)
checks whether something is inxs
, and<(3)
(if implemented) checks whether something is less than 3, etc. Dispatching on something likeCurry2{typeof(in), ...}
would be a bit obscure, so I opted for.CompareTo{in, ...}
instead