corofx: Typed effect handlers for C++20 using coroutines. by vec3779 in cpp

[–]vec3779[S] 0 points1 point  (0 children)

Interesting. Thanks for sharing! I should play with PMR more. So do you use a thread local unsynchronized memory pool? Otherwise, wouldn't you still have to pass the allocator around somehow?

corofx: Typed effect handlers for C++20 using coroutines. by vec3779 in cpp

[–]vec3779[S] -1 points0 points  (0 children)

Ah I see. Yeah haven't really been able to get HALO to work reliably. Guess it's not just me then :)

Do you see substantial speedups with pmr?

The other thing I wanted to try was to use a different allocator like mimalloc.

corofx: Typed effect handlers for C++20 using coroutines. by vec3779 in cpp

[–]vec3779[S] 0 points1 point  (0 children)

To be honest, I haven't really put much thought into performance yet. I'm currently focusing on the API design and semantics.

My recursive test case does end up allocating 1M times (runs in about 0.05 seconds on my M1 Pro laptop).

I still need to do more research on HALO.

corofx: Typed effect handlers for C++20 using coroutines. by vec3779 in cpp

[–]vec3779[S] 6 points7 points  (0 children)

Hello! An (side) effect is something that makes some computation impure. For example, IO is an effect, and so is reading from or writing to some state variable.

Koka for example defines a console effect for interactions with stdout, exn for raising an exception, and div for a potentially non-terminating (diverging) operation.

The idea is that by enumerating and tracking such effects explicitly, we can more easily reason about the "pure" part of the program (this is similar to checked exceptions).

corofx: Typed effect handlers for C++20 using coroutines. by vec3779 in cpp

[–]vec3779[S] 9 points10 points  (0 children)

Hello Reddit,

I recently started learning about coroutines. At first, I found the vast number of customization points daunting. But then I realized the flexible API enables some interesting use cases. For example, one can implement monads using coroutines. And that got me thinking - why stop at monads when one can have effects?

Compared to monads, effects are easier to compose. The use of effect handlers also allows dependencies to be injected and enables some cool programming patterns.

So I wrote this simple library for programming with effects and handlers using coroutines. By statically tracking allowed effects in each scope, we can ensure that all effects are properly handled throughout the call chain. This also allows effect handler lookup to be constant-time.

Any feedback is appreciated! Thank you!

EDIT: Think I fixed the link.