đź“ťFunction color

tags

§ Programming Language

source

What Color is Your Function?

Colored functions is when a language has different kinds of function with different ways to call them that creates a division and pain.

Examples

  • sync/async functions. Callbacks, promises, async/await keywords—they all create a distinction

  • generator function in JS

Solutions

  • In Haskell and Go, there is no distinction between sync/async functions. They all look the same and are called the same way. The code looks sync, but in reality, the language runtime parks the green thread on IO and switches to a different thread.

  • § Continuation, call with current continuation can be hidden within an async function, so the call looks perfectly normal.

  • Zig functions are colorless—Zig has (optional) M:N concurrency.

Backlinks