WinGHCi 中的输入重定向
我知道我可以从命令提示符执行以下操作:
$ 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'
I know I can do the following from a command prompt:
$ runghc WC < quux.txt
How do I do this in WinGHCi? I know I have to first load the file like this:
Prelude> :load WC
But then what? This doesn't work:
*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'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看提供的IO例程:
http://www.haskell.org/tutorial/io.html< /a>
另一个值得一看的地方是:
http://book.realworldhaskell.org/read/io。 html
我认为你需要以不同的方式编写你的程序。 WC 应通过文件句柄进行参数化。然后您可以在 GHCi 上执行
wc (openFile "quux.txt" ReadMode)
。然后,将 main 函数定义为 main = wc stdin ,以保持命令提示符处的输入重定向正常工作。Look at the IO routines provided:
http://www.haskell.org/tutorial/io.html
Another place to look is:
http://book.realworldhaskell.org/read/io.html
I think you need to write your program differently. WC should be parameterized by the file handle. Then you can do
wc (openFile "quux.txt" ReadMode)
at GHCi. Then you define your main function asmain = wc stdin
to keep the input redirection at the command prompt working.