{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreigzrqj2h52zszpftvq3nxty3meqdlymz4cj67bpwgvjsczef3sch4",
"uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3moaldie2ex52"
},
"path": "/t/haskells-missing-mutable-reference-type/14248?page=3#post_47",
"publishedAt": "2026-06-14T09:14:02.000Z",
"site": "https://discourse.haskell.org",
"tags": [
"writeUserData"
],
"textContent": "BurningWitness:\n\n> 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”.\n\nMaybe 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).\n\nSuppose 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:\n\n\n data Severity\n\n writeUserData ::\n (Severity -> String -> IO ()) ->\n (forall a. (Severity -> Severity) -> IO a -> IO a) ->\n IO ()\n\n\nwhere 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?\n\nImportant condition: as the author of `writeUserData` _I do not want to fix the interpretation of`modifySeverity`_.\n\nFor 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.\n\nHow are you imagining implementing `writeUserData` in a thread-safe way where the severity modification is open to interpretation by the caller, without `IOScopedRef`?",
"title": "Haskell's missing mutable reference type"
}