# Fixing the Piping/Chaining/Partial Application Issue (Rev 2)

**URL:** <https://discourse.julialang.org/t/fixing-the-piping-chaining-partial-application-issue-rev-2/90408>\
**Category:** Internals & Design\
**Tags:** proposal, piping, chaining, partial-evaluation, threading\
**Created:** [November 17, 2022, 3:36pm UTC](https://discourse.julialang.org/t/fixing-the-piping-chaining-partial-application-issue-rev-2/90408 "2022-11-17T15:36:57Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [November 18, 2022, 6:49am UTC](https://discourse.julialang.org/t/fixing-the-piping-chaining-partial-application-issue-rev-2/90408/7 "2022-11-18T06:49:49Z")

</div>

* * *

## _A Fun (and productive) Experiment_

A repeated complaint about “tight-currying” is that it binds too tightly for a lot of the common expressions we might wish for. For example, how do we express 1 + x - 2?

```julia
julia> demo" 1 + _ - 2 "
ERROR: MethodError: no method matching -(::Fix1{typeof(+), Int64}, ::Int64)

```

Oh no! An error! That’s because “tight-currying” was greedy, and now we’re trying to subtract an integer from a function instead of just having a lambda that represents the entire expression.

But remember the point of simple syntax with consistent rules, is that it’s composable with other syntax and operators. So maybe we can solve the problem with… wait for it… _composition!_ _(ba-dum-tsss)_

```julia
julia> Base.:-(x::Fix, y) = Fix2(-, y) ∘ x

julia> demo" 1 + _ - 2 "
-(_, 2) ∘ +(1, _)

julia> demo" 1 + _ - 2 "(3)
2

```

Yay!

Here’s another example: \sin(\cos(x)):

```julia
julia> Base.sin(x::Fix) = sin ∘ x

julia> demo" sin(cos(_)) "
sin ∘ cos(_)

julia> demo" sin(cos(_)) "(1)
0.5143952585235492

```

Composing tight currying with function composition. A thing of beauty.

Now, because _any object_ can be a function, maybe this behavior shouldn’t be constrained to just `Fix` objects…

![BatmanThinkingGIF](https://global.discourse-cdn.com/julialang/original/3X/2/d/2d085f0197ab09f668b53283eed9ae4b1dbdd5dc.gif)

If nothing else though, the type `Fix` makes it explicit that it’s a _partial function_ rather than any arbitrary function or object, and therefore this behavior could be intended, so it seems safe enough to explore.

---

_[View the full topic](https://discourse.julialang.org/t/fixing-the-piping-chaining-partial-application-issue-rev-2/90408)._
