Haskell Program to multiply two numbers

Program

main = do
 let a = 3
 let b = 6
 putStrLn "Product of two numbers"
 print (a * b)

This Haskell program multiplies two numbers and prints the result.

  1. main = do

    • Defines the main function where input and output operations take place.
  2. let a = 3 and let b = 6

    • Declares two immutable variables, a and b, with values 3 and 6, respectively.
    • let is used to define variables in Haskell.
  3. putStrLn "Product of two numbers"

    • Prints a message to the console.
    • putStrLn is used to display a string with a newline at the end.
  4. print (a * b)

    • Computes the product of a and b (3 * 6).
    • print is used to display the result on the console.

Output

$ ghc multiply_two_numbers.hs 
[1 of 1] Compiling Main             ( multiply_two_numbers.hs, multiply_two_numbers.o )
Linking multiply_two_numbers ...
$ ./multiply_two_numbers 
Product of two numbers
18