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.
-
main = do
- Defines the main function where input and output operations take place.
-
let a = 3
andlet b = 6
- Declares two immutable variables,
a
andb
, with values3
and6
, respectively. let
is used to define variables in Haskell.
- Declares two immutable variables,
-
putStrLn "Product of two numbers"
- Prints a message to the console.
putStrLn
is used to display a string with a newline at the end.
-
print (a * b)
- Computes the product of
a
andb
(3 * 6
). print
is used to display the result on the console.
- Computes the product of
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