[Haskell-cafe] Reference monad

Joshua Ball sciolizer at gmail.com
Sat Mar 12 04:18:59 CET 2011


Suppose I want the following functions:

newRef :: a -> RefMonad (Ref a)
readRef :: Ref a -> RefMonad a
writeRef :: Ref a -> a -> RefMonad ()

for some appropriate data Ref = ...

Obviously these functions are already satisfied by IORefs and STM.

But if I wanted to implement my own (for fun)... would it be possible?
Particularly, in a pure way, without unsafePerformIO?

runRefMonad :: RefMonad a -> a

I could try to do it with a state monad, and keep all of the refs in a
Data.Map, but then I would have to solve the garbage collection
problem, so that doesn't really work.

Josh "Ua" Ball

More information about the Haskell-Cafe mailing list