
Hi, Is there a way to run 'ghc -e' taking input from standard input? I would like to use it in a pipe. Thanks, Maurício

On Nov 5, 2007 1:46 PM, Maurício
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"] G

On Nov 5, 2007 2:41 PM, Graham Fawcett
On Nov 5, 2007 1:46 PM, Maurício
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...? =) -Brent

Hi,
Is there a way to run 'ghc -e' taking input from standard input? (...)
It seems to me that you can use getContents, et. al., as you would from any other Haskell program: (...)
hm, which raises the question of exactly what Maurício meant. (...)
Actually, what I want is to select a region of text from emacs and get back the result of that evaluated as haskell code. So, I need something that is fast to type, since I'll use it all the time. Maybe I should learn how to write a small shell script that in turn would call xargs ghc. Maurício

On Nov 6, 2007, at 0:16 , Maurí cio wrote:
Actually, what I want is to select a region of text from emacs and get back the result of that evaluated as haskell code. So, I need something that is fast to type, since I'll use it all the time. Maybe I should learn how to write a small shell script that in turn would call xargs ghc.
You might want to take a look at Shim: http://shim.haskellco.de/trac/ -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

Brandon S. Allbery KF8NH escreveu:
On Nov 6, 2007, at 0:16 , Maurí cio wrote:
Actually, what I want is to select a region of text from emacs and get back the result of that evaluated as haskell code. So, I need something that is fast to type, since I'll use it all the time. Maybe I should learn how to write a small shell script that in turn would call xargs ghc.
You might want to take a look at Shim: http://shim.haskellco.de/trac/
Both 'shim.haskellco.de/trac' and 'shim.haskellco.de' says "500 Internal Server Error". Just 'haskellco.de' says "Nothing to see here - move along". What was I supposed to see there? Maurício

On Nov 6, 2007, at 0:48 , Maurí cio wrote:
Brandon S. Allbery KF8NH escreveu:
Actually, what I want is to select a region of text from emacs and get back the result of that evaluated as haskell code. So, I need something that is fast to type, since I'll use it all the time. Maybe I should learn how to write a small shell script that in turn would call xargs ghc. You might want to take a look at Shim: http://shim.haskellco.de/
On Nov 6, 2007, at 0:16 , Maurí cio wrote: trac/
Both 'shim.haskellco.de/trac' and 'shim.haskellco.de' says "500 Internal Server Error". Just 'haskellco.de' says "Nothing to see here - move along". What was I supposed to see there?
Huh, that's unfortunate. The code is on http://code.haskell.org/shim at least. Shim is a small external program and a collection of elisp which adds "live" typechecking and expression evaluation (among other things) to Emacs haskell-mode. I didn't have much luck with it myself, but I use xemacs instead of FSF and Shim (and, for that matter, haskell- mode!) don't play well with xemacs. (the README still references the URL I gave you, so maybe this is a temporary outage...) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

Maurício
Actually, what I want is to select a region of text from emacs and get back the result of that evaluated as haskell code. So, I need something that is fast to type
M-| xargs ghc -e almost works - but ghc -e evaluates only a single argument, so you need to enclose the region with quotes (and escape any quotes inside it). A bit of elisp could probably do it fairly easily. -k -- If I haven't seen further, it is by standing in the footprints of giants

Actually, what I want is to select a region of text from emacs and get back the result of that evaluated as haskell code. So, I need something that is fast to type
M-| xargs ghc -e
almost works - but ghc -e evaluates only a single argument, so you need to enclose the region with quotes (and escape any quotes inside it). A bit of elisp could probably do it fairly easily.
Cool! I tried: M-| xargs -0 ghc -e and it worked well in all examples I tried. Thanks for your tips, Maurício

interact :: (String -> String) -> IO () is a very handy function for
ghc -e, e.g.
ghc -e 'interact $ lines . map (show . (*2) . read) . unlines'
will multiply the number on every line by 2. (interact takes a
function which maps from entire input to entire output)
On 05/11/2007, Graham Fawcett
On Nov 5, 2007 1:46 PM, Maurício
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"]
G _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (6)
-
Brandon S. Allbery KF8NH
-
Brent Yorgey
-
Graham Fawcett
-
Ketil Malde
-
Maurício
-
Rodrigo Queiro