How to run a haskell application in emacs - haskell mode?

2.9k views Asked by At

Code in helloworld.hs :

main = do
putStrLn "Hello, what's your name?"
name <- getLine
putStrLn ("Hey " ++ name ++ ", you rock!")

Application tested in Terminal:

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!

helloworld.hs loaded in emacs - haskell major mode:

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>

Now, How to (What is the procedure? ) test it in emacs - haskell mode environment? (I believe, while I am using emacs - haskell mode , there should be no need to switch over to terminal.)

1

There are 1 answers

2
Nicolas Dudebout On BEST ANSWER

To do something similar to what you did on the command line you need to load your program in ghci (which you have done) and then call the main method (which you can do by just typing main at the prompt).