[Haskell-cafe] Replacing stdin from within Haskell
ok at cs.otago.ac.nz
Fri Jun 10 05:59:14 CEST 2011
> On 9 Jun 2011, at 17:01, Brandon Allbery wrote:
>> On Thu, Jun 9, 2011 at 07: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' ?
>> File descriptors/file handles are per process, not per thread, on
>> (almost?) every OS ghc supports. You'll need to create a full
There is actually a non-sequitur here.
There is file descriptor 0, which is indeed per-process,
and there is the thing that the Prelude functions like
getChar read from.
There is no law of logic, physics, or computation that
says these have to be the same thing.
There are plenty of programming languages (Pop, Ada, Prolog, and
Common Lisp spring to mind, oh yes, and BCPL) where the default input
stream can switched without affecting file descriptor 0 at all.
For example, in Common Lisp, the default input stream is whatever is
the value of the dynamic variable *STANDARD-INPUT*.
I understood the OP's question to mean "does Haskell allow rebinding
of what _it_ calls standard input", which would be YES for Pop, Ada,
Prolog, and Lisp, just as it is NO for C.
More information about the Haskell-Cafe