Implementing RefMonads in Haskell without ST,IO
Ashley Yakeley
ashley@semantic.org
Tue, 03 Jun 2003 19:12:17 -0700
In article <0ede01c3265e$4736c960$8476a841@TIMDELL>,
"Tim Sweeney" <tim@epicgames.com> wrote:
> class Monad m => RefMonad m r | m -> r where
> newRef :: a -> m (r a)
> readRef :: r a -> m a
> writeRef :: r a -> a -> m ()
>
> Is it possible to actually implement a working instance of RefMonad in
> Haskell, without making use of a built-in monad like IO or ST? If so, I'd
> love any tips -- I've been making good use of monads for a while, but can't
> figure this one out.
You certainly wouldn't be able to do this for any monad M which had:
performM :: forall a. M a -> a;
...because it wouldn't be type-safe: you'd be able to construct coerce
:: a -> b just as you can with unsafePerformIO.
--
Ashley Yakeley, Seattle WA