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

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -