When writing a haskell script, get syntax error near unexpected token

无人久伴 提交于 2020-01-14 12:33:26

问题


When I write a simple script and pass it to runhaskell, it works fine, but not when I add a shebang and try executing it directly. The script is this:

#!/usr/local/bin/runhaskell

import Data.List (intercalate)

main :: IO ()
main = putStrLn $ intercalate " " $ map show [1..10]

If I try $ runhaskell count.hs bash prints 1 2 3 4 5 6 7 8 9 10 as expected, but if I try ./count.hs I get the following error:

./count.hs: line 3: syntax error near unexpected token `('
./count.hs: line 3: `import Data.List (intercalate)'

Is this error originating in bash or runhaskell? And how do I fix it?


回答1:


Try using:

#!/usr/bin/env runhaskell
...

Note: this is a feature/issue with OSX where shebang interpreters are required to be binaries. See Shebang pointing to script (also having shebang) is effectively ignored for more details.



来源:https://stackoverflow.com/questions/25880705/when-writing-a-haskell-script-get-syntax-error-near-unexpected-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!