Live data from Hacker News

WasmFX: Effect Handlers for WebAssembly

wasmfx.dev

31–40 of 44 posts

Re: WasmFX: Effect Handlers for WebAssembly

#31
post #21
post #10

Earlier quoted context omitted.

The problem with abstracting control flow has always been the ease of composition within a program. I'm not sure if algebraic effects make that better, although I like the simplest form (exceptions with resume) for error handling. It's kind of like abelian groups and hyper graphs. They generalize many domains very nicely, and are an attractive abstraction. But it turns out they're too abstract for any individual doma…

But that’s the point…? it’s webassembly not JavaScript or Python. You aren’t really expected to write any of this by hand, even if it’s basically what async functions do under the hood when you type await whatever.

The point, as exhibited by the practical issues around Scheme’s call/cc, is that it can be very hard to make different libraries work together when each of them makes use of such control-flow primitives. It definitely doesn’t happen by default—if you just use them at the same time, the result will run, but it won’t make sense (or obey the individual libraries’ invariants).

So if you’re happy to fence off the generality at the language-implementation level and only ever use one language at a time, there’s no problem. Even if you’re fencing it off at the ABI level it could work, though practical implementations of that are between sparse and nonexistent. But if you’re allowing the user (libraries?) to actually make use of the platform—and anything else feels like a disservice to me—you’ll have to confront the (non-)composability problem.

At the same time, I have to note that algebraic effects were explicitly conceived as a more composable primitive (compared to monad transformers, initially). I can’t see how they’d solve the finally/dynamic-wind problem, for example, but I haven’t looked into them that deep, either, and given their designers are not ignorant of all this, I’m curious to see what they came up with.

Re: WasmFX: Effect Handlers for WebAssembly

#32
post #14

Earlier quoted context omitted.

> they were all weird shit that I expect other people to use libraries for in most cases. The theory with algebraic effects is that you'd use them to implement those libraries. Most application code won't be implementing new types of effects, but exceptions, generators, async, and who knows what else can be implemented at the library level instead of the language level. In theory it's a single abstraction that can be…

My point is that it's incredibly rare to actually need such abstractions.

But then, there is a need to make the noise generated by error handling, async, generators, etc. to disappear. Though I doubt it's doable with our current paradigm; we're pushing against the limit of working directly with plaintext, single-source-of-truth code.

Re: WasmFX: Effect Handlers for WebAssembly

#34
post #21

Earlier quoted context omitted.

But that’s the point…? it’s webassembly not JavaScript or Python. You aren’t really expected to write any of this by hand, even if it’s basically what async functions do under the hood when you type await whatever.

The point, as exhibited by the practical issues around Scheme’s call/cc, is that it can be very hard to make different libraries work together when each of them makes use of such control-flow primitives. It definitely doesn’t happen by default—if you just use them at the same time, the result will run, but it won’t make sense (or obey the individual libraries’ invariants). So if you’re happy to fence off the generali…

Call/cc is generally considered a bad primitive now, superseded by delimited continuations that compose nicely.

Re: WasmFX: Effect Handlers for WebAssembly

#35

Earlier quoted context omitted.

That's okay; _using_ WebAssembly is getting easier bit by bit. Features like this one allow the high level programming language features you know and love to be implemented efficiently behind the scenes.

But they make making WASM implementations harder to make.

People said this about GC but then I implemented a WASM interpreter with GC support and it wasn't very hard to do. This FX proposal would introduce... 6 more instructions I think? Not bad. Especially compared to something like the SIMD extension which feels like it's adding a million instructions.

Re: WasmFX: Effect Handlers for WebAssembly

#36
post #14

Earlier quoted context omitted.

> they were all weird shit that I expect other people to use libraries for in most cases. The theory with algebraic effects is that you'd use them to implement those libraries. Most application code won't be implementing new types of effects, but exceptions, generators, async, and who knows what else can be implemented at the library level instead of the language level. In theory it's a single abstraction that can be…

My point is that it's incredibly rare to actually need such abstractions.

I use delimited continuations all the time if the language exposes an interface for them. Coroutines are great to have around. I also use async/await whenever I have to write JS. Seems this proposal really covers the bases for control flow which is great.

Re: WasmFX: Effect Handlers for WebAssembly

#37

This is an exciting proposal. We have delimited continuations in Guile Hoot, a Scheme to WASM compiler, but because there's no stack switching there's more overhead than there should be.

The moment I saw "continuations" I wondered if it was a proposal by some of the Spritely Institute people partially for the sake of Hoot! But your reply suggests it's not?

Re: WasmFX: Effect Handlers for WebAssembly

#38
post #10

I first heard of algebraic effects in a presentation about Unison recorded at Strangeloop. Realizing that exceptions, async, generators, and continuations could all be unified and implemented on top of one language feature was mind expanding. It looks like the juicy details are in the Explainer: https://github.com/WebAssembly/stack-switching/blob/main/pro...

The problem with abstracting control flow has always been the ease of composition within a program. I'm not sure if algebraic effects make that better, although I like the simplest form (exceptions with resume) for error handling. It's kind of like abelian groups and hyper graphs. They generalize many domains very nicely, and are an attractive abstraction. But it turns out they're too abstract for any individual doma…

> Just personally, I can count on one hand the number of algorithms I've written where weird control flow was necessary to make the algorithm easier, and they were all weird shit that I expect other people to use libraries for in most cases.

Async/await or error handling is not "weird control flow". In many codebases you would have more functions that use those than not.

Re: WasmFX: Effect Handlers for WebAssembly

#39

This is an exciting proposal. We have delimited continuations in Guile Hoot, a Scheme to WASM compiler, but because there's no stack switching there's more overhead than there should be.

The moment I saw "continuations" I wondered if it was a proposal by some of the Spritely Institute people partially for the sake of Hoot! But your reply suggests it's not?

Nope, not by us, but we are keeping our eye on it!

Re: WasmFX: Effect Handlers for WebAssembly

#40
post #10

Earlier quoted context omitted.

The problem with abstracting control flow has always been the ease of composition within a program. I'm not sure if algebraic effects make that better, although I like the simplest form (exceptions with resume) for error handling. It's kind of like abelian groups and hyper graphs. They generalize many domains very nicely, and are an attractive abstraction. But it turns out they're too abstract for any individual doma…

WASM is used to implement all kinds of control flow in other languages, so here it makes a lot of sense to have a lower level abstraction. The languages on top of WASM will still have exceptions, generators, etc.

I was thinking the same thing: surely the needs of low-level languages intended as compilation targets are different from languages intended to be programmed in directly? Especially if the goal is to be able to accommodate different high-level language paradigms, which WASM seems to be aiming for.
Post reply on HN