External Publication
Visit Post

Haskell's missing mutable reference type

Haskell Community [Unofficial] June 14, 2026
Source

tomjaguarpaw:

That is, child threads inherit the value from the parent at the time of forking. Modifications in the parent after fork are not observed.

Sounds great. Not very clear from the article that that’s the intended semantics though!

So I guess my API question is whether this is best thought of as a new kind of thread-local variable. Is there anything that you can do with your IOScopedRef API that you couldn’t do with a InheritedThreadLocalIORef? (I imagine the API would be pretty much identical to that for IORef - just the behaviour would be different)

Thus far, we haven’t had any support for thread-local variables in GHC, as people have managed workarounds with Map ThreadId IORef or whatever. But I don’t think we have the tools to do that for a version where the value is inherited by child threads - we’d need a hook to run on thread creation or something. So it does seem like something that might need support in GHC.

Discussion in the ATmosphere

Loading comments...