<br><br><div class="gmail_quote">On 10 June 2011 06:43, Richard O&#39;Keefe <span dir="ltr">&lt;<a href="mailto:ok@cs.otago.ac.nz">ok@cs.otago.ac.nz</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im"><br>
On 10/06/2011, at 1:11 AM, Erik Hesselink wrote:<br>
<br>
&gt; On Thu, Jun 9, 2011 at 13:40, Neil Davies &lt;<a href="mailto:semanticphilosopher@gmail.com">semanticphilosopher@gmail.com</a>&gt; wrote:<br>
&gt;&gt; Anyone out there got an elegant solution to being able to fork a haskell thread and replace its &#39;stdin&#39; ?<br>
&gt;<br>
&gt; If you don&#39;t mind being tied to GHC you can use hDuplicateTo from<br>
&gt; GHC.IO.Handle [1]. You can also use dupTo from the unix package [2],<br>
&gt; but that ties you to unix-like platforms instead.<br>
&gt;<br>
&gt; Erik<br>
&gt;<br>
&gt; [1] <a href="http://hackage.haskell.org/packages/archive/base/latest/doc/html/GHC-IO-Handle.html#v:hDuplicateTo" target="_blank">http://hackage.haskell.org/packages/archive/base/latest/doc/html/GHC-IO-Handle.html#v:hDuplicateTo</a><br>


<br>
</div>That replaces stdin for *every* Haskell thread.<br>
<div class="im"><br>
&gt; [2] <a href="http://hackage.haskell.org/packages/archive/unix/latest/doc/html/System-Posix-IO.html#v:dupTo" target="_blank">http://hackage.haskell.org/packages/archive/unix/latest/doc/html/System-Posix-IO.html#v:dupTo</a><br>


<br>
</div>That alters file descriptor 0 for *every* Haskell thread.<br>
<br>
As I understand the original poster&#39;s question, it would be<br>
paraphrased as &quot;can the association between the default input stream<br>
used by getChar and the rest be changed for ONE thread in a Haskell<br>
program by some method that does NOT have any effect on any other<br>
thread in the same OS process&quot;.  Or to put it another way, &quot;do I<br>
really have to pass a handle around to all these functions in my<br>
thread?&quot;<br>
<br>
And the answer would seem to be &quot;there is no reason in principle<br>
why this *couldn&#39;t* be supported, but it *isn&#39;t*; there are no<br>
C-style thread-local global variables.  Yes, you do have to pass<br>
that handle around more than you would like to.&quot;<br>
<div><div></div><div class="h5"><br></div></div></blockquote><div><br></div><div>Could implicit parameters be used for this purpose?</div><div><br></div><div><a href="http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/other-type-extensions.html">http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/other-type-extensions.html</a></div>

<div><br></div><div>Alexander</div></div>