cda-group / arc

Programming Language for Continuous Deep Analytics
https://cda-group.github.io/arc/
44 stars 6 forks source link

RFC: Lambda tasks #320

Closed segeljakt closed 2 years ago

segeljakt commented 3 years ago

This RFC is about adding "lambda-tasks" which are tasks that can be written inline, like lambda-functions. Currently it is possible to write tasks and functions as top-level items.

fun succ(x: i32): i32 {
    x + 1
}
task Succ(): ~i32 -> ~i32 {
    loop {
        on event => emit succ(event)
    }
}

It is also possible to write lambda-functions:

task Map(f: fun(i32):i32): ~i32 -> ~i32 {
    loop {
        on event => emit f(event)
    }
}
fun test(s: ~i32): ~i32 {
    s | Map(fun(event): event + 1)
}

However it is currently not possible to write tasks as inline. A motivation for adding this feature is it will reduce the verbosity of writing simple tasks. Furthermore, this is a feature which Ray does not support. I propose the following addition:

Expr ::=
  | task ( <Params> ) : <Expr>
  | ...

Lambda-tasks have one input and output stream. The type of a lambda-task is inferred from its context. This allows tasks to be constructed as expressions:

fun test(s: ~i32): ~i32 {
    s | task(): loop {
        on event => emit event + 1
    }
}

The above will desugar into the following:

task <anonymous>() {
    loop {
        on event => emit event + 1
    }
}
fun test(s: ~i32): ~i32 {
    s | <anonymous>()
}

We can apply lambda-lifting to also allow tasks capture variables.

segeljakt commented 2 years ago

Should now be supported