jud*_*ent -1 haskell compilation
我刚开始使用“使用Haskell编程”一书来学习haskell。我要尝试做的第一个想法就是简单地从本书中编译世界示例。我在hello.hc文件中的代码是:
main = do
printStrLn "Hello!"
Run Code Online (Sandbox Code Playgroud)
我使用命令运行ghc
ghc hello.hc
Run Code Online (Sandbox Code Playgroud)
但是我得到的只是一个错误!
hello.hc:1:1: error:
warning: data definition has no type or storage class
main = do
^
hello.hc:1:1: error:
warning: type defaults to 'int' in declaration of 'main' [-Wimplicit-int]
hello.hc:1:8: error:
error: expected expression before 'do'
main = do
^
`gcc.exe' failed in phase `C Compiler'. (Exit code: 1)
Run Code Online (Sandbox Code Playgroud)
我的Haskell平台版本为8.01,
typ*_*ris 11
重命名hello.hc,以hello.hs和尝试
ghc hello.hs
Run Code Online (Sandbox Code Playgroud)
再次。
呼唤
ghc --help
Run Code Online (Sandbox Code Playgroud)
在我的编译器上解释(省略了部分用法):
For each input file, the phase to START with is determined by the
file's suffix:
- .lhs literate Haskell unlit
- .hs plain Haskell ghc
- .hc C from the Haskell compiler gcc
- .c C not from the Haskell compiler gcc
- .s assembly language as
- other passed directly to the linker ld
The phase at which to STOP processing is determined by a command-line
option:
-E stop after generating preprocessed, de-litted Haskell
(used in conjunction with -cpp)
-C stop after generating C (.hc output)
-S stop after generating assembler (.s output)
-c stop after generating object files (.o output)
Run Code Online (Sandbox Code Playgroud)
如果您尝试用编译test.hc,gcc那只是从C编译器得到的错误消息。
[nix-shell:~]$ gcc -x c -std=c99 -o test test.hc
test.hc:1:1: warning: data definition has no type or storage class
main = do
^~~~
test.hc:1:1: warning: type defaults to ‘int’ in declaration of ‘main’ [-Wimplicit-int]
test.hc:1:8: error: expected expression before ‘do’
main = do
^~
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
70 次 |
| 最近记录: |