[Haskell-cafe] How can i safely change the value of specified key ?

Ketil Malde ketil at malde.org
Thu Oct 22 05:21:33 EDT 2009


zaxis <z_axis at 163.com> writes:

>>>value <- readIORef aaa
>>>writeIORef aaa (f value) 

> then aaa will *point to* a new value. 

Exactly.  That's what IORefs are, references pointing to contents that
can be changed in the IO monad.

> The original value will be Garbage Collected, right ?

Yes, unless something else is holding on to it.

> Is [(1,1),(2,2),(3,3)] been regarded as a hash? 

It's a list of pairs.  You can treat it as an association list using
e.g. 'lookup' from Data.List, if that's what you mean.

> If not, what is the best way to change it to [(1,1),(2,2222),(3,3)] in
> function `f` ? 

Not sure if there's anything in Data.List, but you could do something
like: 

  f xs = (2,2222) : filter ((/=2) . fst) xs

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants


More information about the Haskell-Cafe mailing list