Haskell Program to subtract two numbers
Program
main = do
let a = 20
let b = 10
putStrLn "Difference of two numbers is:"
print (a - b)
This Haskell program subtracts two numbers and prints the result.
-
main = do
- Defines the main function where input and output operations take place.
-
let a = 20
andlet b = 10
- Declares two immutable variables,
a
andb
, with values20
and10
, respectively. let
is used to define variables in Haskell.
- Declares two immutable variables,
-
putStrLn "Difference of two numbers is:"
- Prints a message to the console.
putStrLn
is used to display a string with a newline at the end.
-
print (a - b)
- Computes the difference between
a
andb
(20 - 10 = 10
). print
is used to display the result on the console.
- Computes the difference between
Output
$ ghc subtract_two_numbers.hs
[1 of 1] Compiling Main ( subtract_two_numbers.hs, subtract_two_numbers.o )
Linking subtract_two_numbers ...
$ ./subtract_two_numbers
Difference of two numbers is:
10