我在练习时遇到问题,无法理解错误。 这应该是一个简单的练习args:
import System.IO
import System.Environment
main= do
args < - getArgs
nomeficheiro <- return( args !! 0)
putStrnLn ( "Name is" ++ nomeficheiro)
然后我应该运行它:$ ./comando James
错误:
<interactive>:51:1:
parse error on input ‘$’
Perhaps you intended to use TemplateHaskell
我已经阅读了关于args的其他疑问,我没有找到任何可以帮助我的答案
答案 0 :(得分:6)
$ ./comando James
并不意味着要在GHCi上运行。相反,该行开头的$
表示应在bash / cmd / shell中运行以下行,GHCi中不:
# in your favourite shell, in the correct directory ./comando James
如果您想在GHCi中使用参数运行main
,可以使用:main args
:
ghci> :main James
您当前的代码未正确缩进,因此请务必修复此问题。此外,您可以使用let nomeficheiro = head args
代替… <- return …
。请注意,如果您的计划没有提供任何参数,这可能会导致问题,因为head []
会调用error
。