{
  "id": 14919477,
  "title": "Writing stateful effect handlers in EYG",
  "url": "https://urgent.news/2026/10/16/writing-stateful-effect-handlers-in-eyg",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-16T09:28:51.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://eyg.run/guides/advanced-effects"
  },
  "original_language": "en",
  "account": "In the context of managing effects in EYG, it is often necessary to maintain state outside of the computation that raises the effects. Consider an Increment effect that requires tracking the current count, or a handler for StandardOut that accumulates a list of all messages written during testing. The following example demonstrates a stateful Increment effect. Each handle expression is associated with a single effect label. Handlers can be nested to handle multiple effects, but one must be cautious in managing the same state between different handlers. This design choice aims to keep the type system simple, although the restriction may be relaxed in the future. If you require multiple effectful operations, you have two options. The counter value can be incremented and retrieved using the get and increase functions, which serve as the public interface for the stateful operation.\n\nA generic Update effect allows for transforming the current state into a new state. However, this approach is only feasible if you have control over the effect design, which is not always the case. For instance, when testing a library using the Get and Increase effects, one might need to bounce the effects onto a new effect that you have control over. When type checking the following code snippet, an error will be encountered: \"this expression has a recursive type.\" This error is not immediately apparent. The issue arises because the type of f appears in the return type of the Get effect row within the main function. When f is called, its effects are unified with the effects present in the current function block, which is the main block. As a result, a recursive type is constructed, leading to the aforementioned error. It is strongly recommended not to return functions from effects due to this limitation.",
  "summary": null,
  "key_points": [
    "Stateful effects require tracking state outside computation in EYG",
    "Increment effect uses get and increase functions for state management",
    "Generic Update effect allows state transformation but has type limitation"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}