我知道我可以从命令提示符执行以下操作:
$ runghc WC < quux.txt我如何在WinGHCi中做到这一点?我知道我必须首先像这样加载文件:
Prelude> :load WC但是然后呢?这不起作用:
*Main> WC < quux.txt
<interactive>:1:1: Not in scope: data constructor `WC'
<interactive>:1:6: Not in scope: `quux'
<interactive>:1:11: Not in scope: `txt'发布于 2011-07-28 02:59:00
查看提供的IO例程:
http://www.haskell.org/tutorial/io.html
另一个值得关注的地方是:
http://book.realworldhaskell.org/read/io.html
我认为你需要用不同的方式来写你的程序。WC应该由文件句柄参数化。然后你可以在GHCi上做wc (openFile "quux.txt" ReadMode)。然后将主函数定义为main = wc stdin,以保持命令提示符处的输入重定向正常工作。
https://stackoverflow.com/questions/6849648
复制相似问题