
On Fri, 2008-03-28 at 00:02 +0200, Ariel J. Birnbaum wrote:
Two questions came to mind while thinking of memory references in Haskell:
1. Is there a "standard" equivalent of the following:
class (Monad m) => MonadMemory m r | m -> r where new :: a -> m (r a) read :: r a -> m a write :: r a -> a -> m ()
This has come up a few times and been written by many Haskellers (usually called MonadRef.) The problem is the functional dependencies. Any choice you make is either too limiting or too annoying to use and it was never agreed which would be best.
What kind of axioms should an instance of this class satisfy?
There are quite a few obvious ones, but I'm not sure it's particularly necessary.
2. How would a "pure" instance of this class look like (obvious unsafePerformIO-based solutions aside)? Is it even possible in pure Haskell?
The issue here is a type one, not a semantics one. I believe the only way to purely get such an interface (in current Haskell) is to use unsafeCoerce. Other than that, it's a straightforward state monad.