I am trying to learn Haskell from Haskell Road to Logic and came across this example:
mnmInt :: [Int] -> Int
mnmInt [] = error "empty list"·
mnmInt [x] = x
mnmInt (x:xs) = min x (mnmInt xs)
I understand the functions takes a list of Int
-
Checks if empty
if not
checks if it's a list with 1 int if so return x
if not
plug mnmInt with xs parameter to min.
how does it reach the base case? what does the xs stand for?
min implementation:
min' :: Int -> Int -> Int
min' x y | x <= y = x
| otherwise = y
doesn't take an array.