5

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
  • Is that the correct path to runhaskell? Because that does look like a shell error. Is runhaskell itself a script with a shebang? What system/OS is this? Commented Sep 17, 2014 at 1:52

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, that worked. But why? I did which runhaskell to get the path, and running /usr/local/bin/runhaskell count.hs in bash worked fine. How come it didn't work in the shebang?
Not sure, but your code works fine on both my Linux systems (Debian with GHC 7.4 & Arch with GHC 7.8).
@RamithJayatilleka I'm willing to bet it has something to do with runhaskell being a shell script that calls ghc with some arguments.
Added info on OSX behavior.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.