Search code examples
haskellpointfree

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

Solution

  • 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.