3

capslocker.hs has following code:

import Control.Monad  
import Data.Char  
main = forever $ do  
    putStr "Give me some input: "  
    l <- getLine  
    putStrLn $ map toUpper l  

haiku.txt has following contents:

I'm a lil' teapot  
What's with that airplane food, huh?  
It's so small, tasteless 

In the terminal, I am able to do:

optimight@optimight:~$ cat haiku.txt  
I'm a lil' teapot  
What's with that airplane food, huh?  
It's so small, tasteless  

And this:

optimight@optimight:~$ cat haiku.txt | ./capslocker  
Give me some input: I'M A LIL' TEAPOT  
Give me some input: WHAT'S WITH THAT AIRPLANE FOOD, HUH?  
Give me some input: IT'S SO SMALL, TASTELESS  
Give me some input: capslocker: <stdin>: hGetLine: end of file 

How to test the same (as done in terminal) in emacs23 - haskell mode? Please guide.

Please note that, in emacs - haskell mode, I have tried following:

GHCi, version 7.4.1: http://www.haskell.org/ghc/  :? for help  
Loading package ghc-prim ... linking ... done.  
Loading package integer-gmp ... linking ... done.  
Loading package base ... linking ... done.  
Prelude> :load "/home/optimight/capslocker.hs"  
[1 of 1] Compiling Main      ( /home/optimight/capslocker.hs, interpreted )  
Ok, modules loaded: Main.  
*Main> cat haiku.txt | ./capslocker  
<interactive>:3:15: parse error on input `|'   
*Main>
Vitus
  • 11,822
  • 7
  • 37
  • 64
Optimight
  • 2,989
  • 6
  • 30
  • 48
  • Another useless use of cat... `./capslocker – Daniel Wagner Aug 03 '12 at 23:57
  • @DanielWagner : Sir, I am an absolute beginner. Just going through LYAH for good. What are actual scenario/s where cat can be used properly? – Optimight Aug 04 '12 at 00:19
  • 2
    Not really a Haskell thing, but... ["The purpose of cat is to concatenate (or 'catenate') files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process."](http://partmaps.org/era/unix/award.html) – Daniel Wagner Aug 04 '12 at 00:27

1 Answers1

4

From the ghci prompt, you can call shell commands by prefixing with :!.

*Main> :! cat haiku.txt | ./capslocker

It ought to work the same in emacs.

Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431