Before we can talk about what right and wrong we need to know what the semantics of IVars should be.<br><br><div class="gmail_quote">On Dec 8, 2007 7:12 PM, Marc A. Ziegert &lt;<a href="mailto:coeus@gmx.de">coeus@gmx.de</a>
&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">many many answers, many guesses...<br>let&#39;s compare these semantics:<br><div class="Ih2E3d">
<br>readIVar :: IVar a -&gt; IO a<br></div>readIVar&#39; :: IVar a -&gt; a<br>readIVar&#39; = unsafePerformIO . readIVar<br><br>so, we do not need readIVar&#39;. it could be a nice addition to the libraries, maybe as &quot;unsafeReadIVar&quot; or &quot;unsafeReadMVar&quot;.
<br>but the other way:<br><br>readIVar v = return $ readIVar&#39; v<br><br>does not work. with this definition, readIVar itself does not block anymore. it&#39;s like hGetContents.<br>and...<br><br>readIVar v = return $! readIVar&#39; v
<br><br>evaluates too much:<br>&nbsp;it wont work if the stored value evaluates to 1) undefined or 2) _|_.<br>&nbsp;it may even cause a 3) deadlock:<br><br>do<br> &nbsp;writeIVar v (readIVar&#39; w)<br> &nbsp;x&lt;-readIVar v<br> &nbsp;writeIVar w &quot;cat&quot;
<br> &nbsp;return x :: IO String<br><br>readIVar should only return the &#39;reference&#39;(internal pointer) to the read object without evaluating it. in other words:<br>readIVar should wait to receive but not look into the received &quot;box&quot;; it may contain a nasty undead werecat of some type. (Schrödinger&#39;s Law.)
<br><br>- marc<br><br><br><br><br><br>Am Freitag, 7. Dezember 2007 schrieb Paul Johnson:<br><div><div></div><div class="Wj3C7c">&gt; Conal Elliott wrote:<br>&gt; &gt; Oh. &nbsp;Simple enough. &nbsp;Thanks.<br>&gt; &gt;<br>&gt; &gt; Another question: &nbsp;why the IO in readIVar :: IVar a -&gt; IO a, instead
<br>&gt; &gt; of just readIVar :: IVar a -&gt; a? &nbsp;After all, won&#39;t readIVar iv yield<br>&gt; &gt; the same result (eventually) every time it&#39;s called?<br>&gt; Because it won&#39;t necessarily yield the same result the next time you run
<br>&gt; it. &nbsp;This is the same reason the stuff in System.Environment returns<br>&gt; values in IO.<br>&gt;<br>&gt; Paul.<br>&gt; _______________________________________________<br>&gt; Haskell mailing list<br>&gt; <a href="mailto:Haskell@haskell.org">
Haskell@haskell.org</a><br>&gt; <a href="http://www.haskell.org/mailman/listinfo/haskell" target="_blank">http://www.haskell.org/mailman/listinfo/haskell</a><br>&gt;<br><br><br></div></div><br>_______________________________________________
<br>Haskell mailing list<br><a href="mailto:Haskell@haskell.org">Haskell@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/haskell" target="_blank">http://www.haskell.org/mailman/listinfo/haskell</a><br>
<br></blockquote></div><br>