Haskell's missing mutable reference type
michaelpj:
Sounds great. Not very clear from the article that that’s the intended semantics though!
OK, this is supposed to be clear from loggerExampleConcurrently. I’ll see if I can clarify that.
michaelpj:
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
IOScopedRefAPI that you couldn’t do with aInheritedThreadLocalIORef? (I imagine the API would be pretty much identical to that forIORef- just the behaviour would be different)
How would the behaviour differ? Do you mean that InheritedThreadLocalIORef could be modified within a thread like an IORef? If so then it would need a function of type
InheritedThreadLocalIORef a -> a -> IO ()
which isn’t in the IOScopedRef API. But IOScopedRef could be implemented in terms of InheritedThreadLocalIORef. I just don’t like the semantics of the latter. It would allow you to observe whether you’re running in a forked thread. See “the interaction between the semantics of thread creation and of IOScopedRef are good” in the Concurrency section.
What’s the use of having thread local state that allows non-scoped modifications?
Discussion in the ATmosphere