[Haskell-cafe] ghc -e with standard input

Brent Yorgey byorgey at gmail.com
Mon Nov 5 14:47:52 EST 2007

On Nov 5, 2007 2:41 PM, Graham Fawcett <graham.fawcett at gmail.com> wrote:

> On Nov 5, 2007 1:46 PM, Maurí­cio <briqueabraque at yahoo.com> wrote:
> > Hi,
> >
> > Is there a way to run 'ghc -e' taking input
> > from standard input? I would like to use it
> > in a pipe.
> It seems to me that you can use getContents, et. al., as you would
> from any other Haskell program:
> $ echo hello there mauricio | ghc -e "print =<< (Control.Monad.liftM
> (reverse . words)) getContents"
> ["mauricio","there","hello"]

hm, which raises the question of exactly what Maurí­cio meant.  Maurí­cio,
if you mean you want to do ghc -e "some code which gets its data from
standard input", then Graham's solution is exactly what you want.  If you
mean you want to have ghc -e run some code which itself comes from standard
input, then you want xargs (just do a man xargs to see how to use it).  In
retrospect I'm guessing that Graham answered your real question...? =)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071105/4d952c1d/attachment.htm

More information about the Haskell-Cafe mailing list