Thanks, Brandon!! I understand most of what you say but let me ponder!<br><br>Kind regards, Vasili<br><br><div class="gmail_quote">On Wed, Jul 2, 2008 at 1:07 AM, Brandon S. Allbery KF8NH &lt;<a href="mailto:allbery@ece.cmu.edu">allbery@ece.cmu.edu</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;"><div style=""><br><div><div class="Ih2E3d"><div>On 2008 Jul 2, at 1:42, Galchin, Vasili wrote:</div>
<br></div><blockquote type="cite"><div class="Ih2E3d">&nbsp;&nbsp; &nbsp; &nbsp;errno &lt;- throwErrnoIfMinus1 &quot;aioError&quot; (c_aio_error&nbsp; p_aiocb)<br><br></div><div class="Ih2E3d">&quot;ghc&quot; thinks that &quot;Errno&quot; should be an instance of &quot;Num&quot;:<br>
 <br>System/Posix/Aio.hsc:117:15:<br>&nbsp;&nbsp;&nbsp; No instance for (Num Errno)<br></div></blockquote><br></div><div>I expect so it can compare it to -1(throwErrnoIfMinusOne). &nbsp;But if the return value is actually an errno and not -1 to indicate error (which it is if I read the manpage correctly), you don&#39;t want throwErrnoIfMinus1 anyway; I suspect you want to wrap the return value of c_aio_return (which should be IO CInt) in an Errno constructor, then use errnoToIOError if you really want to raise an IOError.</div>
<div><br></div><div>(What were you expecting for &quot;count&quot;? &nbsp;I see none, just an errno.)</div><div><br></div><div>Note that it *never* returns -1; it returns 0 for successful completion for the aiocb, EINPROGRESS if it&#39;s still working, and the appropriate errno if it failed.</div>
<div><br></div><div>You might want to decide if you want to use the aio_return style interface or something more Haskell-ish before designing this part of the API. &nbsp;If you want to stick close to the C interface:</div><div>
<br></div><div>aioReturn :: AIOCB -&gt; IO (AIOCB, Errno)</div><div class="Ih2E3d"><div>aioReturn aiocb =&nbsp;do</div>&nbsp;&nbsp; allocaBytes (#const sizeof(struct aiocb)) $ \ p_aiocb -&gt; do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; poke p_aiocb aiocb<br></div>&nbsp;&nbsp; &nbsp; &nbsp;err &lt;- c_aio_return&nbsp; p_aiocb<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; aiocb &lt;- peek p_aiocb<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (aiocb, Errno err)<div><br></div><div>I&#39;d actually consider something more Haskellish, e.g. a variant of StateT IO where the state is the aiocb and errno, the errno initialized to eINPROGRESS and set by aioReturn and aioError (and once aioReturn is called, it can&#39;t be called again so return the cached value if needed).</div>
<div><br></div><div> <span style="border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div style="">
<span style="border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span style="border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div>
<font face="Monaco"><span style="font-family: Monaco;"><span style="font-family: Monaco;">--&nbsp;</span></span></font></div><div><font face="Monaco"><span style="font-family: Monaco;"><span style="font-family: Monaco;">brandon s. allbery [solaris,freebsd,perl,pugs,haskell] <a href="mailto:allbery@kf8nh.com" target="_blank">allbery@kf8nh.com</a></span></span></font></div>
<div><font face="Monaco"><span style="font-family: Monaco;"><span style="font-family: Monaco;">system administrator [openafs,heimdal,too many hats] <a href="mailto:allbery@ece.cmu.edu" target="_blank">allbery@ece.cmu.edu</a></span></span></font></div>
<div><font face="Monaco"><span style="font-family: Monaco;"><span style="font-family: Monaco;">electrical and computer engineering, carnegie mellon university &nbsp; &nbsp;KF8NH</span></span></font></div><span style="border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 11px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><br>
</span></span></span></div></span> </div><br></div></blockquote></div><br>