
value <- readIORef aaa writeIORef aaa (f value)
then aaa will *point to* a new value. The original value will be Garbage Collected, right ? BTW, Is [(1,1),(2,2),(3,3)] been regarded as a hash ? If not, what is the best way to change it to [(1,1),(2,2222),(3,3)] in function `f` ? Bulat Ziganshin-2 wrote:
Hello zaxis,
Thursday, October 22, 2009, 11:28:14 AM, you wrote:
aaa <- newIORef ([]::[(Int,Int)]) writeIORef aaa [(1,1),(2,2),(3,3)]
then if i want to change aaa to [(1,1),(2,222),(3,3)] , what's the best way ? re-write aaa is not permitted.
it's the only way. in Haskell, you have *immutable* values. aaa is a reference to immutable value. you can mutate reference so it will point to another immutable value but you cannot change this value.
there are two ways to make aaa==[(1,1),(2,222),(3,3)]. first, you can apply function to whole value:
value <- readIORef aaa writeIORef aaa (f value)
second, you may create list of IORefs, tuple of IORefs and so:
a <- newIORef (1,1) ... let aaa = [a,b,c]
now aaa is a immutable list of mutable IORefs. of course, you can create IORef pointing to list of IORefs too
-- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- View this message in context: http://www.nabble.com/How-can-i-safely-change-the-value-of-specified-key---t... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.