With the filename cat.cs
, on linux I get
$ ghc cat.cs
/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/ld:cat.cs: file format not recognized; treating as linker script
/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/ld:cat.cs:1: syntax error
So indeed, since GHC doesn't know how to handle .cs
files, it passes them as is to gcc for linking, gcc doesn't know either, so falls back to regarding it as a linker script, which of course doesn't turn out so well.
But you can tell GHC that it should treat whatever file you give it as, say a .hs
file,
$ ghc -x hs cat.cs
[1 of 1] Compiling Main ( cat.cs, cat.o )
Linking cat ...
runghc
on the other hand doesn't care what the file is named, it tries to interpret the file as normal Haskell source, except if it has the extension .lhs
, then it tries to interpret it as literate Haskell.
cat.hs
orcat.cs
? Naming it ascat.hs
and useghc cat.hs -o cat
works for me (on Linux). – kennytm