Typesafe MRef with a regular monad

George Russell ger@tzi.de
Fri, 06 Jun 2003 18:17:55 +0200


In fact I think these Typesafe MRef's are exactly equivalent
to dynamic types.  In other words, if you've got one,
you've got the other.  Ralf Hinze has just shown that
if you have dynamic types you can implement Typesafe MRef.

The reverse implementation would be something like

 > data Dynamic = FM ()
 >
 > toDyn :: a -> Dynamic
 > toDyn a = insert empty () a
 >
 > fromDynamic :: Dynamic -> Maybe a
 > fromDynamic fm =
 >    let
 >       bogus :: Key () a
 >       (_,bogus) = insert empty () undefined
 >    in
 >       lookup fm bogus