External Publication
Visit Post

Haskell's missing mutable reference type

Haskell Community [Unofficial] June 9, 2026
Source

Unless I’m totally misreading something, the logging example doesn’t capture the logger. Everything that accesses it also takes it as a parameter. So it’s really equivalent to

loggerExample :: IO ()
loggerExample = do
  let logger = newLogger 0
  logMsg logger 1 "Getting user"
  user <- getUser
  logMsg logger 1 ("Is VIP: " <> show (isVip user))
  let modification = if isVip user then (+ 10) else id
  d <- do
    -- Instead of overriding it with a continuation, we can just shadow the variable
    -- (the (<-) and pure are necessary since regular lets are recursive and don't allow shadowing)
    logger <- pure (modifySeverity logger modification)
    logMsg logger 0 "Getting data"
    getData user
  writeData d
  logMsg logger 0 "Done"

and then 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

Discussion in the ATmosphere

Loading comments...