Partial Application brackets without underscores

That’s really neat, that x.[i] and x.{i} are unclaimed syntax! (and they parse!)

HeheheLaughGIF

If you want to play around with your ideas a bit, using my demo code for the Fix partial applicator, you can do this:

Function Currying with []

julia> f(a...) = a
f (generic function with 1 method)

julia> Base.getindex(f::Union{Function, Fix}, i) = FixFirst(f, i)

julia> f[:a][:b][:c]
f(:a, _..., )(:b, _..., )(:c, _..., )

julia> f[:a][:b][:c](1, 2, 3)
(:a, :b, :c, 1, 2, 3)

Setting Arbitrary Indices with Pairs

julia> f(a...) = a
f (generic function with 1 method)

julia> Base.getindex(f::Function, i::Pair{Int,<:Any}...) = 
           Fix{((x[1] for x ∈ i)...,), 0}(f, (x[2] for x ∈ i)...)

julia> f[2=>:a, 4=>:b, 6=>:c]
f(_, :a, _, :b, _, :c, _..., )

julia> f[2=>:a, 4=>:b, 6=>:c](1, 2, 3)
(1, :a, 2, :b, 3, :c)

Unfortunately, the generation of an applicator using Pairs is type-unstable. You can use Tuples instead though!

Do note, that the two methods are incompatible (i.e., you’d want to pick one or the other; to have both would cause inconsistent behavior).

Overall, given my rebuttal above, I don’t see this proposal as solving any problems in my proposal. Further, as currying is a subset of partial application, having syntax sugar only for partial application is probably good enough. Fixing arguments by position number, rather than visual position, I also don’t see as valuable enough to devote specialized syntax (and you can already do it fairly conveniently using my Fix constructor).

But who knows! I could be wrong. Maybe play around with it, and see if you can find examples where this is preferable?

1 Like