我想将此程序作为独立程序运行:
module Main where main = putStrLn "Hello world!"
so I typed in ghci:
--make -o hello Main.hs
but when I want to run it with ./hello
I get a parse error for ./
.
I tried also ghc --make -o hello Main.hs
but then I get an "Variable not in scope: ghc" error.
Can somebody tell me, what I'm doing wrong?
解决:命令必须在外壳中运行,ghc和Main.hs必须在同一目录中
Short answer: You do not compile the program in the
ghci
shell.It looks like you are running this in
ghci
(based on the error messageVariable not in scope
).ghci
is a Haskell shell, but you do not write commands to compile or run a program in the Haskell shell itself. You run these in a shell likebash
,sh
,fish
, etc.So you open a terminal window, and then you can
cd
to the correct directory where theMain.hs
file is located, then you can write:or for a Windows system, you can add a
.exe
extension:and finally you can run this program, for example by writing
./hello
in the shell.