Typesafe MRef's

Ralf Hinze ralf@informatik.uni-bonn.de
Fri, 13 Jun 2003 17:16:08 +0200


Am Freitag, 13. Juni 2003 17:12 schrieb George Russell:
> Keith wrote (snipped)
>
>  > But George Russell's implementation relied on looking up something in
>  > one map with a key obtained from another map.  I thought type-safe
>  > MRefs should disallow this.
>
> However if you disallow lookup up in one map with a key from another,
> then Ralf Hinze's solution of putting the value inside the key
> uses no type extentions and works perfectly well (though is probably
> not quite what was intended).

Here is the modified version of `update':

 update                       :: (Typable b) => FM k -> Key k a -> a -> FM k
 update (FM bs) (Key k r) b   =  FM ((k, Dyn r b) : bs)