Typesafe MRef's

George Russell ger@tzi.de
Fri, 13 Jun 2003 18:29:45 +0200


Keith Wansbrough wrote (snip)
> No, because update should not return a new key, it should update the 
> value of the same key.  In other words,
> 
> let (m1,k) = insert empty "A"
>     m2 = update m1 k "B"
> in
> lookup m2 k
> 
> should give "B", not "A", just like with MRefs.

So what does the function
    insert2 val1 val2 =
       let
          (m1,k1) = insert empty (Just val1)
          (m2,k2) = insert m1 (Just val2)
          m3 = update m2 k1 Nothing
       in
          isJust (lookup m3 k2)
return?  It looks to me as if it returns True if val1 and val2 have
different types, False if they have the same type.  So you have now
got a way of comparing two types for equality, and so a rather
roundabout reimplementation of Dynamic.