Okay, I had to spend 40 minutes figuring out what this is, and I’m still not sure.
Am I correct to understand that the problem you’re looking to solve is that of a user-definable implicit global context, which can be adjusted locally, e.g.
overriding :: Contextual a -> (a -> a) -> (forall b. IO b -> IO b) -- deeply magical
contextual x :: Contextual Int -- still magical
contextual x = 5
foo = do
a <- getContextual x
print a
--- Library user doesn't get to implement anything above this line
-- Prints number 7
main = overriding x (+2) foo
I assumed if a feature like this were to exist it’d be on the compiler to collect all the “contextual” references upfront. This wouldn’t be mutable from user perspective, so I wouldn’t bring up IORef at all when talking about it.