3

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

Optimight
  • 2,989
  • 6
  • 30
  • 48

1 Answers1

5

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

Nicolas Dudebout
  • 9,172
  • 2
  • 34
  • 43
  • Is there a way send "main" in GHCI with a key stroke? (without loosing the focus from edit window) – oshyshko Sep 02 '14 at 11:15
  • 2
    ...found the solution here http://stackoverflow.com/questions/13213717/function-to-evaluate-haskell-in-ghci-while-editing-source-file-using-emacs – oshyshko Sep 02 '14 at 11:24