Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It looks very nice! I'm digging the simple Haskell-ish syntax.

The example on Types is not compiling as it is. The last line should be something like:

    console.log (getName {firstName: "John", lastName: "Doe"})


I do like Haskell syntax, but only because it allows partial application of functions.

No partial application allowed here, so what is the point? =\

   let add a b = a + b
   let add2 = add 2
Does not work.

   let fact a = 
   if a == 0 then 
      1
   else
      (fact (a-1)) * a
Does not support recursion like this either. The "functional" description brought my expectations too high I think.

It compiles to very lean Javascript though, so that's a big plus.


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.


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!


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.


Currying is very easy to implement in terms of lexical closures.


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.


It's an early version. Maybe, currying would be added in one of upcoming releases.


I have the same issue on Chrome 15.0.874.121 m. Also the tracing monad example 404s for me.


Sorry, I deployed it late last night and didn't test it.

That should be fixed.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: