initial commit
This commit is contained in:
14
lab01/max.hs
Normal file
14
lab01/max.hs
Normal file
@@ -0,0 +1,14 @@
|
||||
maxNum :: [Integer] -> Integer
|
||||
|
||||
maxNum [] = error "empty list"
|
||||
maxNum [x] = x
|
||||
maxNum (x:xs) = let m = maxNum xs in if x > m then x else m
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
print (maxNum [1,2,3])
|
||||
print (maxNum [4])
|
||||
print $ maxNum [7, 12, 0, 99, 46, 12349, 82] -- note the use of the '$' here
|
||||
print $ maxNum [-4, -1, -99, -2]
|
||||
print $ maxNum [7, -9, 12, 0, 99, -3, 46, 12349, 82, -7, 8]
|
||||
print $ maxNum []
|
||||
Reference in New Issue
Block a user