Question: I would like to understand the basics of how to write and execute Haskell program on Linux OS. Can you explain it with a simple example?
Answer: In this article, let us review very quickly how to write a basic Hello World Haskell program and execute haskell program on Linux or Unix OS.
Also, refer to Haskell article on wikipedia to learn about this programming language.
1. Write a Hello World Haskell Program
Create the helloworld program using the Vim editor as shown below.
$ vim helloworld.hs -- hello world example main = putStrLn "Hello, World!"
Note: Comment in Haskell starts with –.
2. Make sure Haskell Compiler is installed on your system
Make sure Haskell compiler is installed on your system as shown below.
$ whereis ghc ghc: /usr/bin/ghc /usr/share/man/man1/ghc.1.gz
Installing haskell ( ghc ) compiler
If you don’t have haskell compiler, install it as shown below.
$ sudo apt-get install ghc6
3. Compile the haskell program
Compile the HelloWorld which will create the HelloWorld executable.
Compile and get a.out.
$ ghc helloworld.hs
Compile and get executable in desired name with -o option.
$ ghc -o helloworld helloworld.hs
4. Execute the haskell Program
Execute by mentioning the program name.
$./a.out Hello, World! $./helloworld Hello, World!
Comments on this entry are closed.
Cripes!!
-rwxrwxr-x 1 chris chris 500103 19-Mar-2010 17:02:14 a.out
Thank you! It worked for me!
Thx