我已经用Haskell编写了一个名为testscript
的脚本,并包含以下代码:
#!/usr/bin/env runhaskell
main = putStrLn "hello"
将脚本设置为可执行后,可以使用./testscript
运行它。但是,当我尝试使用ghci(即使用:l testscript
)加载脚本时,会出现错误。
target `testscript' is not a module name or a source file
如果我将
testscript
重命名为testscript.hs
,然后再次尝试用ghci加载,我会收到错误提示。testscript.hs:1:0: error: invalid preprocessing directive #!
phase `C pre-processor' failed (exitcode = 1)
如果我删除shebang行,它能正常工作。但是每次想在ghci中尝试脚本时都必须添加.hs扩展名,删除顶部行,然后删除.hs扩展名并添加shebang行,这很繁琐(每次想要对其进行更改时都很常见)。有更简单的方法吗?
我正在使用Mac OS X 10.6.8下的ghc版本7.0.3。