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.
Sincerely!
--
View this message in context:
2009/10/22 zaxis z_a...@163.com:
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.
Why do you say that ? You can use again writeIORef of modifyIORef to
change
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
Hello zaxis,
Thursday, October 22, 2009, 11:28:14 AM, you wrote:
then if i want to change aaa to [(1,1),(2,222),(3,3)] , what's the best way
... well, anyway what you are doing isn't very haskellish. it may be
considered as advanced topic but basically, best way to compute
something in Haskell
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,),(3,3)] in function `f` ?
Bulat
zaxis z_a...@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
Hello zaxis,
Thursday, October 22, 2009, 1:03:21 PM, you wrote:
value - readIORef aaa
writeIORef aaa (f value)
then aaa will *point to* a new value. The original value will be Garbage
Collected, right ?
yes, exactly
BTW,
Is [(1,1),(2,2),(3,3)] been regarded as a hash ? If not, what is
f xs = (2,) : filter ((/=2) . fst) xs
It works but not general as `f` still needs to change other value according
to the KEY.
Maybe Data.List will supply what i need.
Ketil Malde-5 wrote:
zaxis z_a...@163.com writes:
value - readIORef aaa
writeIORef aaa (f value)
then aaa will
Hello zaxis,
Thursday, October 22, 2009, 1:03:21 PM, you wrote:
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,),(3,3)] in function `f` ?
f = map (\x@(a,b) - if a==2 then (a,) else x)
or
f xs = [(a, if a==2 then else b) |
2009/10/22 zaxis z_a...@163.com:
f xs = (2,) : filter ((/=2) . fst) xs
It works but not general as `f` still needs to change other value according
to the KEY.
Maybe Data.List will supply what i need.
I don't think Data.List has what you want as-is. The above code is
generalized simply:
replace k v xs = (k,v) : filter ((/=v) . fst) xs
Great ! thanks you very much
minh thu wrote:
2009/10/22 zaxis z_a...@163.com:
f xs = (2,) : filter ((/=2) . fst) xs
It works but not general as `f` still needs to change other value
according
to the KEY.
Maybe Data.List will supply
2009/10/22 zaxis z_a...@163.com:
replace k v xs = (k,v) : filter ((/=v) . fst) xs
Great ! thanks you very much
I'm not sure why you're so much happy:
Assume some function defined as follow:
foo a b c = e x y z a b c
where x = some constant
y = some other constant
z
- Sorry for the late reply on this, I actually sent it last night before I
went to bed but accidentally sent it only to Bulat, re-sending it now for
the entire list -
As Bulat said, it sounds like you're not fully understanding functional
programming. You really should read one of the better
13 matches
Mail list logo