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

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

#!/usr/local/bin/runhaskell

import Data.List (intercalate)

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

If I try $ runhaskell count.hsbash printing 1 2 3 4 5 6 7 8 9 10as 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 a source in bash or runhaskell? And how to fix it?

+4
source share
1 answer

Try using:

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

. / OSX, shebang . . , script ( shebang), .

+6

All Articles