Typesafe MRef with a regular monad

Ashley Yakeley ashley@semantic.org
Wed, 04 Jun 2003 17:57:35 -0700


In article <20030604200734.00006d9e.ddarius@hotpop.com>,
 Derek Elkins <ddarius@hotpop.com> wrote:

> M = (forall s.ST s)
> R = STRef s
> 
> e.g. runST :: (forall s.ST s a) -> a
> 
> you can use the same trick for your own RefMonad.  I'm not sure if this
> will work with RefMonad exactly.  If ST/STRef can be made an instance of
> RefMonad without any trouble though, then I believe it should work.

No, it won't work, fortunately ST is safe this way:

  newSTRef Nothing :: forall a s. ST s (STRef s (Maybe a))

  runST (newSTRef Nothing) :: -- type error, s escapes.

The type error occurs because "forall s. ST s a" cannot be matched with 
"forall s. ST s E" (for some type-expression E) if E contains s (which 
it does in this case).

-- 
Ashley Yakeley, Seattle WA