[Haskell-cafe] Intercept stdin in Haskell

Andrew Gibiansky andrew.gibiansky at gmail.com
Sun Jan 5 20:49:10 UTC 2014


Yeah, I am pretty sure I have no choice but trigger an event when the code
requests input. I think Python is just much more flexible - you can
probably just substitute something that isn't a file for sys.stdin, and
when you call getline() on it it just does what it needs to. Flexible
dynamic languages and all that.

That's an interesting way to go about it. Will look into it, maybe. So far
I've been browsing the source of GHC.IO.Handle in the hopes of finding a
way to do this - maybe use the underlying IORefs in the Handle_ constructor
for the Handle data type in order to unsafeCoerce something... I don't even
know. I'm beginning to think this is just more or less impossible, though.


On Sun, Jan 5, 2014 at 3:42 PM, Rogan Creswick <creswick at gmail.com> wrote:

> On Sun, Jan 5, 2014 at 12:19 PM, Andrew Gibiansky <
> andrew.gibiansky at gmail.com> wrote:
>
>> That's a good idea, but there's no IPython input channel. Instead, the
>> backend (my interpreter) has to *request* input from the frontend, which
>> then supplies this input. The input is entered via a web browser, so
>> there's not even a handle or file descriptor to speak of.
>>
>
> Ugh, so you really do need to trigger an event when the code in the cell
> requests input.  How does python handle this?
>
> Here's a horrible idea, but in the spirit of brainstorming... you could
> run the cell code in a separate app (fork off your interpreter), using
> ptrace (for linux; I'm not sure how to do this on other OSes) to detect
> system calls that involve stdin, and then supply input based on that.
>
> Aside from being tricky to do for all platforms, that's also going to have
> a horrible user experience for any code that loops over std in rapidly to
> get what would otherwise appear as a single input to the user, but I'm
> grasping at straws...
>
> --Rogan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140105/e81892f5/attachment.html>


More information about the Haskell-Cafe mailing list