Skip to content

Comment on Roy — small functional language that compiles to JavaScriptparent

Comments

> I think that the variadic-arguments-are-always-allowed nature of JavaScript is not very compatible with partial application though.

It could be implemented by compiling Roy functions to chains of 1-arg functions, but the amount of recursion and funcalling would probably be expensive (JS is not very good at these).

A SmartEnoughCompiler® you could also see partial application points and craft a partial application right there:

    let add x y = x + y
    console.log (add 1 32)
    let add2 = add 2
    console.log (add2 5)

    var add = function (x, y) { return x + y; };
    console.log(add(1, 32));
    var add2 = function (y) { return add(2, y); };
    console.log(add2(5));
As long as the number of arguments can be understood at compile time (which it can), it's not that hard: if the number of arguments provided make the function's arity reach 0 you partially apply it (and decrease the arity of the result), otherwise you fully apply it.

I decided against outputting like that a while ago but after seeing that example, I can't think of a great reason against it.

I'll have a go and see how well it works. Thanks!

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.