开发者

Applying a haskell function to a .txt file in ghc?

开发者 https://www.devze.com 2023-02-18 09:58 出处:网络
I\'ve currently wrote a program to use on a .txt file but whenever i try to run it i get the error: cat quux.txt | ./wordCount

I've currently wrote a program to use on a .txt file but whenever i try to run it i get the error:

cat quux.txt | ./wordCount

开发者_高级运维
<interactive>:1:14: parse error on input `|'  

Am i typing in my code wrong to work it on the ghc or?


You can't use shell syntax in ghci. You should type the command into the shell instead.


In ghci you can do

 :!<shell command>

To execute a command in the shell e.g.

Prelude> :!pwd
/home/me


You seem to be thinking GHCi is a shell, it isn't. There is no piping and no cat in GHCi.

Once you compile your program just do what you showed in a bash shell:

$ cat rotate.hs | ./rotate

ainm = od
c -< etContentsg
etl sl = inesl c
sw = apm ordsw sl
sr = apm map( ot)r sw
utStrLnp $ nlinesu $ apm nwordsu sr

otr w = ropd 1 w ++ aket 1 w
0

精彩评论

暂无评论...
验证码 换一张
取 消