Haskell's missing mutable reference type

prophet:

the logging example doesn’t capture the logger

Well, the definition of Logger does not use IOScopedRef directly. Logger could be defined in a module that doesn’t even know IOScopedRef exists. The IOScopedRef is captured in the closures that are stored in the Logger value, isn’t it? If not, what do you mean by “capture”?

prophet:

So it’s really equivalent to

Sure, if you inline and use shadowing you can obtain similar behaviour. But what about when you can’t inline everything, because you’re trying to combine code from two independent libraries?

I don’t see the advantage of passing this additional reference around if all you’re doing with it is modifying it in a lexically scoped way like you already can with regular variables

OK, then tell me how I could obtain the same behaviour using a lexically-scoped variable but without IOScopedRef.