3 ms·
Ahh, that's sort of obvious in retrospect, but I was blinded thinking in terms of Haskell where IO protects against such generalization.
by tel 13y ago
Ahh, that's sort of obvious in retrospect, but I was blinded thinking in terms of Haskell where IO protects against such generalization.
- emillon 13y agoThe equivalent Haskell program is import Data.IORef main :: IO () main = do r <- newIORef [] writeIORef r ["Hello"] x <- readIORef r print $ x + 1 return () The reference is bound by "r <-", ie a lambda (as this desugars to ">>= \ r ->"), and lambdas are never generalized (even in ocaml). I think that the reason why it works is that because there is no way to let-bind r except with a toplevel unsafePerformIO.
- tel 13y agoYup, that's precisely what I forgot to think about.