0

I'm curious if there is a specific name for this function in Lambda Calculus

const whatsMyName = f => a => { f(a); return a }

Also, would this be the correct signature?

// (f -> a -> b) -> a -> a

Example

const trace = whatsMyName(console.log)

Thanks!

-- EDIT:

This is just S(K), or Substitution(Constant). I was able to work this out, a more elaborate answer with good references:

Functional programming construct for composing identity and side effect

Specific Answer

https://stackoverflow.com/a/46120634/1560484

Thanks @ftor for comment!

Babakness
  • 2,954
  • 3
  • 17
  • 28

1 Answers1

0

I figured out how to construct it from other combinators. There may not be a special name for it, it is simply derived from K (constant) and S (substitution).

 const K = x => y => x
 const S = f => g => x => f(x)(g(x));
 const whatsMyName = S(K)
 const trace = whatsMyName(console.log)

Edit:

The comment by @ftor points to a more complete answer:

Functional programming construct for composing identity and side effect

Babakness
  • 2,954
  • 3
  • 17
  • 28
  • 1
    look into SKI combinator calculus. Related [q&a](https://stackoverflow.com/a/46120634/6445533). –  Mar 01 '18 at 09:28
  • Wow! Thanks for that link, went straight to my bookmarks on functional programming! – Babakness Mar 01 '18 at 18:09