在 GHCI(版本 9.0.1)中,以下给出了我所期望的:
ghci> import Data.IORef
ghci> ref <- newIORef ([] :: [Int])
ghci> modifyIORef ref (1:)
ghci> readIORef ref
[1]
但是当我以这种方式尝试同样的事情时:
ghci> import Data.IORef
ghci> ref = newIORef ([] :: [Int])
ghci> ref >>= \r -> modifyIORef r (1:)
ghci> ref >>= readIORef
[]
返回一个空列表,就好像修改从未发生过一样。为什么会这样?输出不应该相同吗?