Haskell's missing mutable reference type

I would also like something like this! I wonder if GHCi could support a new top-level form with which I used like

ghci> :with f v

where f :: (a -> IO r) -> IO r for some a and r. Then you’d get a “nested” GHCi block with v :: a in scope, which you could return from with :endwith:

ghci> :with (bracket acquire release) conn
ghci with1> conn
Connection { hostname = "...", ... }
ghci with1> let results = runQuery conn
ghci with1> results
[ Result 1, Result 2 ]
ghci with1> :endwith (head results)
Result 1
ghci>

IOScopedRef could be useful here, but I don’t think it’s a key element.

1 Like