<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 14 Mar 2016, at 8:06 pm, Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" class="">simonpj@microsoft.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="WordSection1" style="page: WordSection1; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span style="font-size: 12pt;" class="">But my rough answer would be: IORefs are really only meant for single-threaded work.  Use STM for concurrent communication.</span></div></div></div></blockquote><div><br class=""></div><div>You can also use atomicModifyIORef for simple things. </div><div><br class=""></div><div><br class=""></div><blockquote type="cite" class=""><div class="WordSection1" style="page: WordSection1; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="border-style: none none none solid; border-left-color: blue; border-left-width: 1.5pt; padding: 0cm 0cm 0cm 4pt;" class=""><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span lang="EN-US" class="">Why can’t GHC tighten the semantics of IORefs so that the bind operation simply means sequential composition? </span></div></div></div></blockquote><div><br class=""></div><div>Part of the problem is that IO encomposes all sorts of computational effects, including ones that don’t have a well defined notion of time. File and network effects are also a problem, not just IORefs. The IO instance of bind composes two IO computations, but the computations themselves could do anything.</div><div><br class=""></div><div>A first step is to split the IO type into more fine grained effects, perhaps ones that can be properly sequentialized and those which can’t (or should not be). Many people have done work on more expressive effect systems, though no system so far has been good enough to want to refactor the GHC base libraries using it.</div><div><br class=""></div><div>On a more philosophical level, Haskell types are statements in a simple predicate logic which does not natively know anything about time. Functions don’t know about time either, so it’s a bit odd to ask a functional operator to do something sequential (at least relative to the real world). In the “awkward squad” paper note that the functional encoding of the bind operator *passes* the world from one place to another -- it is not part of the world, and does not act upon the world itself.</div><div><br class=""></div><div>In recent work on effect systems there are a lot of embeddings of modal logics into the ambient Haskell/predicate logic, and the embeddings then suffer an encoding overhead. AFAIK the future lies in type systems that natively express temporal concepts, rather than needing tricky encodings of them, but we’re not there yet.</div><div><br class=""></div><div>Ben.</div><div><br class=""></div><div><br class=""></div></div></body></html>