For some reason the parser breaks with that factorial definition, but adding spaces in between `a-1` seem to do the trick:
let fact a =
if a == 0 then
1
else
(fact (a - 1)) * a
console.log (fact 5)
Now, it's true that the Haskell syntax does not make that much sense if there is no partial application. I think that the variadic-arguments-are-always-allowed nature of JavaScript is not very compatible with partial application though.
> 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.
Currying is a nice-to-have but definitely not a requirement for a usable functional language. It might be possible to add it to Roy by abusing JavaScript dictionaries and identifying functions that are partially applied but I'm not convinced it's worth the effort.
Sure, but that can get costly fast (at runtime) when the language implementations are not highly optimized for funcalling and recursion (javascript VMs tends not to be), so ideally you'd only use partial application in the underlying (compiler result) code when that's needed rather than have all functions be curried.
The example on Types is not compiling as it is. The last line should be something like: