1

我知道我可以从命令提示符执行以下操作:

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

1 回答 1

4

查看提供的 IO 例程:

http://www.haskell.org/tutorial/io.html

另一个要看的地方是:

http://book.realworldhaskell.org/read/io.html

我认为您需要以不同的方式编写程序。WC 应该由文件句柄参数化。然后你可以wc (openFile "quux.txt" ReadMode)在 GHCi 做。然后,您定义您的主要功能,main = wc stdin以保持命令提示符下的输入重定向正常工作。

于 2011-07-27T18:58:59.807 回答