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 = 3andlet b = 6- Declares two immutable variables,
aandb, with values3and6, respectively. letis used to define variables in Haskell.
- Declares two immutable variables,
-
putStrLn "Product of two numbers"- Prints a message to the console.
putStrLnis used to display a string with a newline at the end.
-
print (a * b)- Computes the product of
aandb(3 * 6). printis 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