Typesafe MRef's

oleg@pobox.com oleg@pobox.com
Wed, 18 Jun 2003 17:02:40 -0700 (PDT)


> 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.

Sorry for the delay: I was out of town. Using the Haskell98
implementation of typesafe MRef posted earlier, the insert2 function
always returns True. To be more precise, the following function,


insert2 val1 val2 =
  let
     (m1,k1) = insert empty () [val1]
     (m2,k2) = insert m1 () [val2]
     m3 = update m2 k1 []
  in
     isJust (lookp m3 k2)

re-written to conform to Simon Peyton-Jones' signature (modulo
renaming of lookup into lookp) and to use lists rather than
Maybes. The universe in the posted code had no maybes, due to my
laziness.

The function continues to always return True even if we replace the
update statement above with
     m3 = update m2 k2 []

The former result is obvious from the fact that keys k1 and k2 indeed
refer to different "cells" so to speak (at least in the posted
implementation of the Simon Peyton-Jones' signature). Therefore,
updating the cell referred to by k1 has no bearing on the cell
referred to by k2.