Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 427
jramm Avatar asked Oct 22 '25 05:10

jramm


1 Answers

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>
like image 78
Ori Drori Avatar answered Oct 23 '25 17:10

Ori Drori



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!