≡ Menu

Haskell Hello World Example: How To Write, Compile and Execute Haskell Program on Linux OS

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!

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 2 comments… add one }

  • Chris F.A. Johnson March 19, 2010, 3:06 pm

    Cripes!!

    -rwxrwxr-x 1 chris chris 500103 19-Mar-2010 17:02:14 a.out

  • Melsi November 16, 2012, 8:05 pm

    Thank you! It worked for me!

Leave a Comment