The OS.IO.poll function in MLton&#39;s Basis library is probably implemented<br>incorrectly.&nbsp; I say &quot;probably&quot;, because the basis library specification<br>leaves a lot to be desired.<br><br>The specification says
<br><br>&nbsp;infoToPollDesc pi<br>&nbsp;&nbsp;&nbsp; returns the underlying poll descriptor from poll information pi. <br><br>I would assume that this means that you get a poll descriptor (&quot;events&quot;<br>flags) that is *equal to* the corresponding poll descriptor that you gave
<br>to poll.&nbsp; In MLton&#39;s implementation this doesn&#39;t necessarily hold, because<br>the implementation derives a poll descriptor from the flags in the poll<br>information (&quot;revents&quot; flags).<br><br>Here is a simple example.&nbsp; Suppose we have (exactly one poll descriptor)
<br><br>&nbsp; val pds = [OS.IO.pollIn (OS.IO.pollOut (OS.IO.pollDesc ioDesc))]<br><br>and then execute<br><br>&nbsp; val ids = OS.IO.poll (pds, NONE)<br><br>I would assume that<br><br>&nbsp; map OS.IO.infoToPollDesc ids = pds<br><br>but this doesn&#39;t necessarily hold in MLton.&nbsp; In MLton&#39;s implementation,
<br>the left hand side may be equal to any one of<br><br>&nbsp; [OS.IO.pollIn (OS.IO.pollOut (OS.IO.pollDesc ioDesc))]<br>&nbsp; [OS.IO.pollIn (OS.IO.pollDesc ioDesc)]<br>&nbsp; [OS.IO.pollOut (OS.IO.pollDesc ioDesc)]<br>&nbsp; [OS.IO.pollDesc
 ioDesc]<br><br>The last, perhaps surprising, case results from the possibility of<br>&quot;revents&quot; flags POLLERR, POLLHUP, and POLLNVAL, which may be set even if<br>the corresponding &quot;events&quot; flags aren&#39;t.
<br><br>All in all, this means that even if the poll descriptor list given to poll<br>contained no duplicates, it may be impossible to associate the returned<br>poll information values to the poll descriptors that you gave to poll.
<br><br>-Vesa Karvonen<br><br>