# Effect composability: actual callstack vs syntactic scope

**URL:** <https://discuss.ocaml.org/t/effect-composability-actual-callstack-vs-syntactic-scope/17536>\
**Category:** Learning\
**Created:** [November 27, 2025, 12:45pm UTC](https://discuss.ocaml.org/t/effect-composability-actual-callstack-vs-syntactic-scope/17536 "2025-11-27T12:45:28Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![dbuenzli](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dbuenzli/32/18_2.png) [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Post date:** [August 12, 2026, 10:41pm UTC](https://discuss.ocaml.org/t/effect-composability-actual-callstack-vs-syntactic-scope/17536/4 "2026-08-12T22:41:15Z")

</div>

@wokalski I gather that it’s too late by now, but the problem that you faced here with Eio has a solution in the just released [affect](https://discuss.ocaml.org/t/ann-affect-0-0-0-a-streamlined-and-natural-concurrency-model-for-ocaml/18451) concurrency model and library via the notion of asynchronous [call handlers](https://erratique.ch/software/affect/doc/Affect/Fun/Async/Call_handler/index.html). See [here](https://erratique.ch/software/affect/doc/cookbook.html#basics_effects) for an example.

It’s not exactly _syntactic scope_ in the sense that you need to manually plug your call handler when you do your [asynchronous function call](https://erratique.ch/software/affect/doc/Affect/Fun/Async/index.html#val-call), but once you have done that it respects the _function scope_: call handlers are inherited and composed with those of child asynchronous function calls. So these child calls will be subject to it unless their own call handlers override it.

That entails at least an operational reconciliation with what you’d expect from syntactic scope – i.e. no `Exception: Stdlib.Effect.Unhandled E` in a subcomputation of `f` if you plugged a handler for `E` when calling `f`.

---

_[View the full topic](https://discuss.ocaml.org/t/effect-composability-actual-callstack-vs-syntactic-scope/17536)._
