Saturday 4 June 2016

Haskell: Find maximum of four numbers


Sample.hs
import Prelude hiding(max)

max :: Int -> Int -> Int
max x y = if (x >= y) then x else y

getMaximum :: Int -> Int -> Int -> Int -> Int
getMaximum w x y z = (w `max` x) `max` (y `max` z)

Prelude> :load Sample.hs
[1 of 1] Compiling Main             ( Sample.hs, interpreted )
Ok, modules loaded: Main.
*Main> 
*Main> getMaximum 10 20 30 40
40
*Main> getMaximum 10 20 40 30
40
*Main> getMaximum 10 40 20 30
40
*Main> getMaximum 40 10 20 30
40


Previous                                                 Next                                                 Home

No comments:

Post a Comment