<br><br><div class="gmail_quote">On 10 June 2011 06:43, Richard O'Keefe <span dir="ltr"><<a href="mailto:ok@cs.otago.ac.nz">ok@cs.otago.ac.nz</a>></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>
> On Thu, Jun 9, 2011 at 13:40, Neil Davies <<a href="mailto:semanticphilosopher@gmail.com">semanticphilosopher@gmail.com</a>> wrote:<br>
>> Anyone out there got an elegant solution to being able to fork a haskell thread and replace its 'stdin' ?<br>
><br>
> If you don't mind being tied to GHC you can use hDuplicateTo from<br>
> GHC.IO.Handle [1]. You can also use dupTo from the unix package [2],<br>
> but that ties you to unix-like platforms instead.<br>
><br>
> Erik<br>
><br>
> [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>
> [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's question, it would be<br>
paraphrased as "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". Or to put it another way, "do I<br>
really have to pass a handle around to all these functions in my<br>
thread?"<br>
<br>
And the answer would seem to be "there is no reason in principle<br>
why this *couldn't* be supported, but it *isn'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."<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>