javascriptfunctional-programmingramda.jspointfreecombinators

Point-free version of g(f(x)(y))


Is there a way to express the following in point-free form:

g(f(x)(y))

It is not a common 'combinator' as far as I can see, though there are perhaps different ways to express it? I am working in Javascript with Ramda.


Solution

  • I can't think of a readable way to create this combinator in a point-free form. However, since the introduction of arrow functions to JS it's pretty easy to create readable combinators. You can also curry them using Ramda's R.curry, instead of manually curry them (f => g => x => y => g(f(x)(y))):

    const { curry, on, identity, multiply, add } = R
    
    const combinator = curry((f, g, x, y) => g(f(x)(y)))
    
    const square = n => n * n;
    
    const squareAddition = combinator(add, square)
    
    const result = squareAddition(1, 2)
    
    console.log(result)
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.28.0/ramda.min.js" integrity="sha512-t0vPcE8ynwIFovsylwUuLPIbdhDj6fav2prN9fEu/VYBupsmrmk9x43Hvnt+Mgn2h5YPSJOk7PMo9zIeGedD1A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>