Haskell's missing mutable reference type

That won’t work, at least not if you want to see intermediate results.
The way you have it, that f function could do anything with its continuation, including discarding it or running it several times.

Like, what would you expect to happen if I did

> :with (\_ -> pure ()) ()
> print 5
???

or

> :with (\io -> io () >> io ())
> print 5
???

You could special case the case where you’re using it with bracket (which calls its continuation exactly once in a predictable way)

> :withBracket acquire release conn
> conn
Connection { hostname = "...", ... }
...
:endwith (head results)

but that’s not really all that different from calling acquire and release yourself.