Haskell Program to print Hello World!


This tutorial will discuss writing a program to print Hello World! in Haskell Programming Language. The Computations in Haskell are done using mathematical functions. In this tutorial, We will discuss different ways to print Hello World! in Haskell.

  • Program to print Hello World! Using the “print” function.

  • Program to print Hello World! Using the “putStr” function.

  • Program to print Hello World! Using the “putStrLn” function.

Example

Program to print Hello World! Using the “print” function

main :: IO()
main = do
-- printing using the function print
   print ("Hello World!")

Output

Hello World!

In the above program, we printed the string “Hello World!” using the function print. Which takes a value(any datatype) as an argument and outputs it to the display console. The function print adds a new line (“
”) character at the end of the output.

Example

Program to print Hello World! Using the “putStr” function

main :: IO()
main = do
-- printing using the function putStr
   putStr ("Hello World!")

Output

Hello World!

In the above program, we printed the string “Hello World!” using the function putStr. Which takes a String as an argument and outputs it to the display console. The putStr function print doesn’t add a new line (“
”) character at the end of the output.

Example

Program to print Hello World! Using the “putStrLn” function

main :: IO()
main = do
-- printing using the function putStrLn
   putStrLn ("Hello World!")

Output

Hello World!

In the above program, we printed the string “Hello World!” using the function putStr. Which takes a String as an argument and outputs it to the display console. The putStr function print adds a new line (“
”) character at the end of the output.

Conclusion

In this tutorial, we discussed three different ways to implement a program to print Hello World in Haskell programming Language.

Updated on: 15-Dec-2022

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements