λ-calculus to js arrow notation transpiler

4

1

Not an interpreter. Arguably a compiler. But I'm talking about a transpiler.

It can be in any language, but it must return js-valid arrow notation code.

The λ-calculus string would be passed as an argument to a function, or the whole program, and in some way the program would return/log/print the string with the js-notation.

Whitespace is not important, if it makes the writing easier.

Only accepted answers are with curry notation for output, not multiple parameters. The λ-calculus notation shorthand for multiple parameters must be considered.

All identifiers will be separated either by a (space), a λ, a . or () (parentheses). They can be more than a single character. Note that if the language has issues with keeping track of characters like λ, then you can cut yourself some slack and use \.

The transpiler doesn't have to evaluate the expression to simplify it, but as long as the statement is equivalent, I'll allow it. It won't gain any extra points.

All unneeded parenthesis can be taken out. x=>x is just as valid as (x=>x) which is just as valid as ((x)=>x) or (x)=>x.

Using non arrow-function javascript features is disallowed, although if you come up with interesting hacks, they might be worth checking out, so feel free to ask if you have something creative.

Efficiency isn't really important, as long as vaguely practical, so answer with least amount of bytes wins

Examples:

λx.x                -> (x)=>x
λx y.x(y)           -> (x)=>(y)=>x(y)
λx.λy.x(y)          -> (x)=>(y)=>x(y)
λs z.s(s z)         -> (s)=>(z)=>s(s(z))
λfoo bar.foo bar    -> (foo)=>(bar)=>foo(bar)
(λa b c.b c a) x y -> ((a)=>(b)=>(c)=>(b(c)(a)))(x)(y)

towc

Posted 2017-03-15T22:50:54.710

Reputation: 346

Question was closed 2017-03-16T02:01:09.543

Are the legal JS forms which do not use excess ()s also fine? i.e. λx.x -> x=>x? – Benjamin Gruenbaum – 2017-03-15T22:52:34.983

yeah. Added them in for clarity. I'll specify it – towc – 2017-03-15T22:53:35.803

1You should talk about the precise definition of a lambda so that the post is self-contained and on-topic. – Conor O'Brien – 2017-03-15T23:30:42.170

1@ConorO'Brien how do you suggest I should do that? Post a few resources indicating what lambda calculus is? Maybe just the wiki page? If there was any question of ambiguity, I would have thought that the examples would answer them – towc – 2017-03-15T23:49:51.307

I agree with Conor. Without an in-challenge explanation of how lambda calculus works, this challenge isn't standalone, and thus is unclear. – Mego – 2017-03-16T00:56:59.070

Any edits or suggestions on how to make it clearer are welcome. I honestly thought adding a list of inputs and outputs was good enough, whether or not you understand lc – towc – 2017-03-16T17:21:26.873

No answers