Haskell's missing mutable reference type

tomjaguarpaw:

Well, I explained how I can get my API from yours.

Yes, and I explained that I have no idea what “reading from the vault” would look like. I’m essentially getting

contextual vault :: Contextual Vault

foo :: IO ()
foo = do
  a <- _ vault
  print a

---

main =
  withScopedIORef vault 5 $ \x ->
    overriding x (+2) $
      foo

with the questions:

  • How is foo expected to access x without breaking type safety? Passing a key is not an answer, that’s still data.

  • What happens if main = foo?

I guess you could solve both of these if IO is an effect that carries x at the type level, but that would require proper type-level programming implemented first.