1

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
4

1 回答 1

8

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 :-)

于 2014-12-11T04:19:04.847 回答