condense9 / hark-lang

A serverless virtual machine
https://guide.condense9.com
Apache License 2.0
108 stars 8 forks source link

The async operator should be able to "lift" functions #19

Open rmhsilva opened 4 years ago

rmhsilva commented 4 years ago

Is your feature request related to a problem? Please describe.

Often, I want to pass a Python function around (e.g. to map), but always call it asynchronously. Currently, the only way to do that is wrap it:

fn foo_async(x) {
  async foo(x)
}
// ...
map(foo_async, items)

Where map takes a function pointer.

Describe the solution you'd like

I'd like to be able to do:

map(async foo, items)

Implementation

At compile-time, async foo should create a new https://wiki.haskell.org/Lifting version of foo which always runs asynchronously. This could work similar to the import lifting (see wrap_foreign_function in https://github.com/condense9/teal-lang/blob/master/src/hark_lang/hark_compiler/compiler.py).

The parser rules would need to be modified too.