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).
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)
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).
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. --KW 8-)
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.
George Russell writes:
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.
I think I'm missing something... why is this? Do you only allow one value of each type? It seems to me that updating k1's value should not affect k2's. --KW 8-)
Keith Wansbrough wrote (snipped)
I think I'm missing something... why is this? Do you only allow one value of each type? It seems to me that updating k1's value should not affect k2's.
Perhaps you could explain what "insert" is meant to do, since it doesn't cite a key value.
I'm thinking newSTRef - allocate a new cell. --KW 8-) -- Keith Wansbrough <kw217@cl.cam.ac.uk> http://www.cl.cam.ac.uk/users/kw217/ University of Cambridge Computer Laboratory.
participants (3)
-
George Russell -
Keith Wansbrough -
Ralf Hinze