helloworld.hs 中的代码:
main = do
putStrLn "Hello, what's your name?"
name <- getLine
putStrLn ("Hey " ++ name ++ ", you rock!")
在终端中测试的应用程序:
optimight@optimight:~$ ghc --make helloworld
[1 of 1] Compiling Main ( helloworld.hs, helloworld.o )
Linking helloworld ...
optimight@optimight:~$ ./helloworld
Hello, what's your name?
John
Hey John, you rock!
在 emacs 中加载 helloworld.hs - haskell 主要模式:
GHCi, version 7.4.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :load "/home/optimight/helloworld.hs"
[1 of 1] Compiling Main ( /home/optimight/helloworld.hs, interpreted )
Ok, modules loaded: Main.
*Main>
现在,如何(程序是什么?)在 emacs - haskell 模式环境中测试它?(我相信,当我使用 emacs - haskell 模式时,应该不需要切换到终端。)
最佳答案
要执行类似于在命令行上执行的操作,您需要在 ghci 中加载程序(您已完成),然后调用 main
方法(只需键入main
在提示符下)。
关于haskell - 如何在 emacs - haskell 模式下运行 haskell 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11708440/