3

capslocker.hs 有以下代码:

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

haiku.txt 有以下内容:

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

在终端中,我能够做到:

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

还有这个:

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 

如何在 emacs23 - haskell 模式下测试相同的(如在终端中所做的)?请指导。

请注意,在 emacs - haskell 模式下,我尝试了以下操作:

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>
4

1 回答 1

4

在 ghci 提示符下,您可以通过添加前缀来调用 shell 命令:!

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

它应该在 emacs 中同样工作。

于 2012-08-03T22:17:52.750 回答