Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there idiomatic pointfree way to call a function with arguments through another functions

We have these functions

foo x1 x2 ... xN =

f1 x =
f2 x =
...
fN x = 

Is there idiomatic pointfree version of this function?

bar x1 x2 ... xn = foo (f1 x1) (f2 x2) ... (fN xN)

edit

If not can we somehow generalize this function to N parameters?

applyF3 f f1 f2 f3 x1 x2 x3 = f (f1 x1) (f2 x2) (f3 x3)
bar = applyF3 foo f1 f2 f3
like image 920
ais Avatar asked Aug 23 '15 10:08

ais


2 Answers

Not really idiomatic:

import Control.Arrow

bar = curry . curry $ (f1 *** f2) *** f3 >>> (uncurry . uncurry $ foo)

Add more curry/uncurrys for more arguments.

The pointful version is much more clear.

like image 81
chi Avatar answered Nov 08 '22 17:11

chi


If we have this set of functions

uncurryPairsN f (x1,(x2,...)) =  f x1 x2 ... xN
curryPairsN f x1 x2 ... xN =  f (x1, (x2, ...))

then

bar = curryPairsN $ uncurryPairsN foo . (f1 *** f2 *** ... *** fN)
like image 25
ais Avatar answered Nov 08 '22 17:11

ais