<div>Please correct me if I'm wrong in any of the reasoning below.</div><div><br></div>Haskell provides the ability the perform partial application on the rightmost arguments.<div><br></div><div>I learned from some pretty smart guys that partial application cannot be emulated with lambas, because they behave differently operationally, e.g.</div>
<div><br></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">e = trace "e"</span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">op = (+)</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new'; font-size: 12px;"><br></span></div><div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">a1 = let f = (op (e 1)) in (f 10, f 100)<br>
</span></div><div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">a2 = let f = (\x -> op (e 1) x) in (f 10, f 100)</span></div><div><br></div><div>a1 and a2 are operationally not the same: a1 will evaluate (e 1) once, a2 will evaluate it twice. </div>
<div><br></div><div>However, Haskell also allows to partially apply the second argument of binary functions (using sections)<br></div><div><br></div><div><div><div><span class="Apple-style-span" style="font-family: 'courier new'; font-size: 12px;">b1 = let f = (`op` (e 1)) in (f 10, f 100)</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new'; font-size: 12px;">b2 = let f = (\x -> (e 1) `op` x) in (f 10, f 100)</span></div><div><br></div></div><div><div><span class="Apple-style-span" style="font-family: 'courier new'; font-size: 12px;"><span class="Apple-style-span" style="font-family: arial; font-size: 13px; "><div>
Again, b1 evaluates (e 1) once, b2 twice.</div><div><br></div><div>b1 is actually the same as</div><div><br></div><div><div><span class="Apple-style-span" style="font-family: 'courier new'; font-size: 12px; ">c1 = let f = ((flip op) (e 1)) in (f 10, f 100)<br>
</span></div><div><span class="Apple-style-span" style="font-family: 'courier new'; font-size: 12px;"><br></span></div><div><div>So for ternary functions we could write more permutations of flip:</div><div><br></div>
<div><div><span class="Apple-style-span" style="font-family: 'courier new'; ">flip3_12 f a1 a2 a3 = f a2 a1 a3</span><br></div><div><span class="Apple-style-span" style="font-family: 'courier new';"><div>flip3_13 f a1 a2 a3 = f a3 a2 a1</div>
<div>flip3_23 f a1 a2 a3 = f a1 a3 a2</div><div><br></div><div><span class="Apple-style-span" style="font-family: arial; "><div>And use these to partially apply any argument </div><div><br></div></span></div></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new'; ">e1 x = trace "e1" x</span></div><div><span class="Apple-style-span" style="font-family: 'courier new'; ">e2 x = trace "e2" x</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new'; "><br></span></div><div><span class="Apple-style-span" style="font-family: 'courier new'; ">op2 :: Int -> Int -> Int -> Int</span><br>
</div><div><span class="Apple-style-span" style="font-family: 'courier new'; ">op2 x y z = x+10*y+100*z</span></div><div><span class="Apple-style-span" style="font-family: 'courier new'; "><br></span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">z1 = let f = (flip3_12 op2) (e1 1) (e2 2) in (f 3, f 4)</span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">z2 = let f = (flip3_13 op2) (e1 1) (e2 2) in (f 3, f 4)</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">z3 = let f = (flip3_23 op2) (e1 1) (e2 2) in (f 3, f 4)</span></div><div><span class="Apple-style-span" style="font-family: 'courier new';"><br>
</span></div><div><span class="Apple-style-span" style="font-family: 'courier new';"><span class="Apple-style-span" style="font-family: arial; "><div>This could be extended to N-ary functions. Haskell doesn't give any special syntactic support for this, but it surely is possible.</div>
<div><br></div><div>Am I missing something here? Is there any easier way to perform "generalized partial application"?<br></div><div><br></div><div><br></div></span></span></div><div><br></div></div></div></div>
</span></span></div></div></div></div></div>