3
votes

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
Your question is how to use REPL (read eval print loop) for Haskell under emacs.Basile Starynkevitch
@Basile Starynkevitch: Okay, so how to use REPL for Haskell under emacs?Optimight
Simply type main at the ghci prompt inside Emacs, or whatever function you would like to test.Sarah

1 Answers

5
votes

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).