What is a max function in Haskell?
Overview
The max function is used to get the maximum of two arguments. We can get the maximum of two integers, two floats, or two characters.
Syntax
max first_argument second_argument
Parameters and return value
This function takes two parameter values to compare and returns the greater value.
Let's have a look at the example below.
Example
main::IO()main = do-- get max of two integersprint(max 5 10)-- get max of two floatsprint(max 154.0 34.0)-- get max of two charactersprint(max 'a' 'A')
Explanation
In the above code:
- Line 5: We use the
maxfunction to get the max of two integer values. - Line 8: We use the
maxfunction to get the max of two float values. - Line 11: We use the
maxfunction to get the max of two characters. We also use theASCIIvalue to compare the characters.