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 = 20andlet b = 10- Declares two immutable variables,
aandb, with values20and10, respectively. letis used to define variables in Haskell.
- Declares two immutable variables,
-
putStrLn "Difference of two numbers is:"- Prints a message to the console.
putStrLnis used to display a string with a newline at the end.
-
print (a - b)- Computes the difference between
aandb(20 - 10 = 10). printis 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