[Haskell-cafe] Replacing stdin from within Haskell
alexander.kjeldaas at gmail.com
Fri Jun 10 10:22:58 CEST 2011
On 10 June 2011 06:43, Richard O'Keefe <ok at cs.otago.ac.nz> wrote:
> On 10/06/2011, at 1:11 AM, Erik Hesselink wrote:
> > On Thu, Jun 9, 2011 at 13:40, Neil Davies <semanticphilosopher at gmail.com>
> >> Anyone out there got an elegant solution to being able to fork a haskell
> thread and replace its 'stdin' ?
> > If you don't mind being tied to GHC you can use hDuplicateTo from
> > GHC.IO.Handle . You can also use dupTo from the unix package ,
> > but that ties you to unix-like platforms instead.
> > Erik
> > 
> That replaces stdin for *every* Haskell thread.
> > 
> That alters file descriptor 0 for *every* Haskell thread.
> As I understand the original poster's question, it would be
> paraphrased as "can the association between the default input stream
> used by getChar and the rest be changed for ONE thread in a Haskell
> program by some method that does NOT have any effect on any other
> thread in the same OS process". Or to put it another way, "do I
> really have to pass a handle around to all these functions in my
> And the answer would seem to be "there is no reason in principle
> why this *couldn't* be supported, but it *isn't*; there are no
> C-style thread-local global variables. Yes, you do have to pass
> that handle around more than you would like to."
Could implicit parameters be used for this purpose?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe