puffnfresh / roy

Small functional language that compiles to JavaScript.
http://roy.brianmckenna.org/
MIT License
836 stars 74 forks source link

`return` broken #155

Open puffnfresh opened 11 years ago

puffnfresh commented 11 years ago

Following example does not work because return is not parsed correctly:

let ioMonad = {
        return: \x -> (\() -> x)
        bind: \action f -> (\() -> 
                             let value = action ()
                             let action2 = f value
                             action2 ()
                           )
      }

let putStrLn line () = console.log line

let main = do ioMonad
    text <- return "hello"
    putStrLn text

main ()
raimohanska commented 11 years ago

Btw, there's another trick in the example: the putStrLn implementation assumes that Roy functions are curried and partially applicable which apparently is not the case. Hence, my working version has also this change:

let putStrLn line = (\() -> console.log line)

In this same experiment I tried to introduce

let const x = (\() -> x)

But that doesn't compile; const seems like a reserved word. Don't know if that's intentional... (If I name it "always" instead, it compiles)