[Haskell-cafe] Intercept stdin in Haskell

Andrew Gibiansky andrew.gibiansky at gmail.com
Sun Jan 5 22:19:06 UTC 2014


I think we found a way! (With a *ton* of help from @aavogt - might actually
be more correct to say he found the way :) )

You can use `hDupTo` to change what a Handle points to. You can use
`mkFileHandle` in GHC.IO.Internal to create a new file handle. You can
implement your own IODevice and BufferedIO datatype to give to
`mkFileHandle` instead of using `Fd`. Then, when your "device" is being
read from, you just implement `newBuffer` and `readBuffer` to do whatever
you need them to.

Results pending.

-- Andrew


On Sun, Jan 5, 2014 at 4:14 PM, Donn Cave <donn at avvanta.com> wrote:

> I bet a quarter you can't do it.  You'd need access to the process state -
> whether it's blocking for I/O and whether one of the units in the input set
> is 0 ("stdin".)  Even if you could get that? you'd have to poll for it,
> which
> would be hideous.
>
> That's the UNIX I/O model.  I've always found it a little annoying, because
> I could do this with the VMS `mailbox' device, analogous to UNIX pipes -
> in various ways a more sophisticated interprocess communication system than
> UNIX's.
>
>         Donn
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140105/ebed6991/attachment.html>


More information about the Haskell-Cafe mailing list