[Haskell-cafe] Replacing stdin from within Haskell

Alexander Kjeldaas 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>
> wrote:
> >> 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 [1]. You can also use dupTo from the unix package [2],
> > but that ties you to unix-like platforms instead.
> >
> > Erik
> >
> > [1]
> http://hackage.haskell.org/packages/archive/base/latest/doc/html/GHC-IO-Handle.html#v:hDuplicateTo
>
> That replaces stdin for *every* Haskell thread.
>
> > [2]
> http://hackage.haskell.org/packages/archive/unix/latest/doc/html/System-Posix-IO.html#v:dupTo
>
> 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
> thread?"
>
> 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?

http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/other-type-extensions.html

Alexander
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110610/173b4de8/attachment.htm>


More information about the Haskell-Cafe mailing list