haskell - What is the purpose of the extra result parameter of atomicModifyIORef? -
the signature of modifyioref
straightforward enough:
modifyioref :: ioref -> (a -> a) -> io ()
unfortunately, not thread safe. there alternative adresses issue:
atomicmodifyioref :: ioref -> (a -> (a,b)) -> io b
what differences between these 2 functions? how supposed use b
parameter when modifying ioref
might read thread?
as stated in comment, without concurrency you'd able write like
modifyandreturn ref f = old <- readioref ref let !(new, r) = f old writeioref r new return r
but in concurrent context, else change reference between read , write.
Comments
Post a Comment