Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functions -> state machines (aka async functions / supsend functions / continuations) #1263

Open
alex-s168 opened this issue Feb 14, 2025 · 2 comments

Comments

@alex-s168
Copy link
Contributor

how this should work in theory

allow functions to be marked as async, which makes the compiler convert the function to a struct which contains all the locals and temporaries, and a step function which takes the current state and returns either a new state or the return value.

this allows for many cool things:

  • yield(): lazy and/or infinite collections
  • lightweight threads: by scheduling for example 32 function calls on a pool of 4 threads
  • async I/O obviously
  • pause a function while some other important event is happening (can also be achieved by other ways)

problems

how to properly integrate that with the existing type system?

@andrew-johnson-4
Copy link
Owner

Functions are proofs, not always stack functions. This has been a design goal since the start.

How it works

let the-transform( dependency1: KnownProperties1, dependency2: KnownProperties2 ) : ResultProperties = (
   transform-step-1( dependency1, other-stuff-1 );
   transform-step-2( dependency2, other-stuff-2 );
   result
);

When designing non-traditional functions think:

  • what do I know before the transformation
  • what do I know after the transformation
  • how do I get from A to B

The type system already works with this design in mind, however the backend doesn't really handle this abstraction cleanly. It still expects mostly traditional functions. However, the Fragment model is a strong backbone to build on, it just currently is in an unfortunate state.

@andrew-johnson-4
Copy link
Owner

Also see early design docs for chain / apply which abstracts this even a little more:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants