External Publication
Visit Post

Haskell's missing mutable reference type

Haskell Community [Unofficial] June 14, 2026
Source

BurningWitness:

I’m in the “pass everything explicitly as arguments” camp, so my question is pretty much “how is doing things the stupid way not enough here”.

Maybe it’s time to have the API design discussion then (and if mods think it’s too off topic for this thread then they can split it off).

Suppose I am thinking of writing a function like writeUserData which has the following type (isomorphic to the one in the linked section), which uses a type Severity which I also define:

data Severity

writeUserData ::
  (Severity -> String -> IO ()) ->
  (forall a. (Severity -> Severity) -> IO a -> IO a) ->
  IO ()

where the first argument is a callback to log messages at a severity and the second argument (call it modifySeverity) locally modifies the severity. What is your alternative to this API?

Important condition: as the author of writeUserData I do not want to fix the interpretation ofmodifySeverity.

For example, when the Severity reaches a certain elevated level the caller may want modifySeverity to obtain a connection to a different logging channel (maybe it starts writing to a file rather than stdout) for the duration of elevated execution (but no longer than that). I want to support that use case.

How are you imagining implementing writeUserData in a thread-safe way where the severity modification is open to interpretation by the caller, without IOScopedRef?

Discussion in the ATmosphere

Loading comments...