1
votes

Heres my code:

factorial :: Integer -> Integer
factorial n = product [1..n]

main = print(factorial 50)

I don't get any errors compiling, but when i run the compiled code

runhaskell test

I get this error:

test:1:1: lexical error at character '\DEL'

What is causing this? How do I solve the problem?

UPDATES

I did a hexdump of the file:

$ hexdump -x test.hs

and got

0000000    6166    7463    726f    6169    206c    3a3a    4920    746e
0000010    6765    7265    2d20    203e    6e49    6574    6567    0a72
0000020    6166    7463    726f    6169    206c    206e    203d    7270
0000030    646f    6375    2074    315b    2e2e    5d6e    6d0a    6961
0000040    206e    203d    7270    6e69    2874    6166    7463    726f
0000050    6169    206c    3035    0029                                
0000057
1
Hex dump your file to see if it has a 0x7f in it.paxdiablo
Nope, no 0x7f. please see editdopatraman
I can't tell the difference between Haskell and a bar of soap but all the examples I can find have runhaskell test.hs (with the extension). Are you sure you're not picking up a binary file called just test somewhere?paxdiablo
@paxdiablo- I think you have it, I just ran runHaskell on the compiled binary, and got the same error message. @dopatraman- runHaskell is an interpreter, it takes source code, if you have a compiled binary you can run it directly.jamshidh
Adjusted your code, by the way. That hex dump shows there's no -- test.hs line at the top.paxdiablo

1 Answers

8
votes

Make sure that you're using runhaskell with the source file test.hs rather than the compiled binary test.

If you've used something like ghc to create an executable file, you can just run that directly, with something like:

./test

Be aware that test is probably not a good name for an executable since it's a built-in command on some shells, something that's burnt me before when my test executable doesn't seem to do what I wanted :-)