Fork-fragile reader-like operations in Haskell
The hs-opentelemetry example is good. The current behaviour is, IMO, utterly unusable for any application that uses concurrency to a significant degree.
The way we’ve solved this at CircuitHub is that we use Effectful, which already implements the correct thread-scoped state behaviour for its own state, provided you use its concurrency wrappers (which we do). So we wrote an effect that tracks the hs-opentelemetry Context inside the effect data, instead of in thread-local storage. That works pretty much perfectly.
Which suggests to me that effectful itself would likely benefit from a thread-and-children-scoped-ioref primitive. However - if you dig into effectful you will find that it actually offers quite the array of options for how its environment should be cloned in various different situations. Perhaps effectful needs this because it’s trying to be quite a general framework, but it’s interesting to think about.
Discussion in the ATmosphere