I published a library which implements this idea; furry.
| # | From | To | Normal | Alternative |
|---|---|---|---|---|
| 1 | a → b → c |
a → c |
f(_, b)(a) |
f(_, b)(a) |
| 2 | a → b → c |
b → a → c |
nope | f(_)(b, a) |
| 3 | a → b → c → d |
b → d |
f(a, _, c)(b) |
f(a, _, c)(b) |
| 4 | a → b → c → d |
a → b → d |
f(_, _, c)(a, b) |
f(_, _, c)(a, b) |
| 5 | a → b → c → d |
a → c → d |
f(_, b)(a, c) |
f(_, b, _)(a, c) |
| 6 | a → b → c → d |
b → a → d |
nope | f(_, _, c, _)(b, a) |
| 7 | a → b → c → d |
c → a → d |
nope | f(_, b)(c, a) |
| 8 | a → b → c → d |
c → b → d |
nope | f(a, _)(c, b) |
| 9 | a → b → c → d |
b → c → a → d |
nope | f(_)(b, c, a) |
| 10 | a → b → c → d |
c → a → b → d |
nope | f(_, _)(c, a, b) |
| 11 | a → b → c → d |
c → b → a → d |
nope | nope |
| 12 | a → b → c → d |
b → a → c → d |
nope | nope |
The alternative has another advantage: You can supply the placeholders in curried fashion, something which is impossible with the normal semantics:
f(a, b, c) === f(_, _, c, _)(b, a) === f(_)(_)(c)(_)(b)(a) === f(_, _, c, _, b, a)
- Any case where the last argument is the placeholder (like
2and8), is equivalent to applyingflipto the function without providing the placeholder. - The alternative method almost provides the full power of
rearg, except for cases like11and12. These kinds of cases would become more common as the arity of the function increases. - The alternative method has exactly the same syntax for the majority of use-cases. Note that only
5differs. These differences will become more abundant as the arity of the function increases. - The alternative method has more consistent behavior; there's no difference between calling your function
f(_)(_)(_)orf(_, _, _).