
On 10 June 2011 06:43, Richard O'Keefe
On 10/06/2011, at 1:11 AM, Erik Hesselink wrote:
Anyone out there got an elegant solution to being able to fork a haskell
On Thu, Jun 9, 2011 at 13:40, Neil Davies
wrote: 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-Hand...
That replaces stdin for *every* Haskell thread.
[2] http://hackage.haskell.org/packages/archive/unix/latest/doc/html/System-Posi...
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... Alexander