3 ms·
I would have written two functions instead where one takes a default argument and the other returns None if the list is empty. In pseudo-Haskell notation:
by howling 6y ago
I would have written two functions instead where one takes a default argument and the other returns None if the list is empty.
In pseudo-Haskell notation:
min1 : Int -> List Int -> Int
min1 def Nil = def
min1 def (Cons x xs) = min1 (def if def <= x else x) xs
min : List Int -> Maybe Int
min Nil = None
min (Cons x xs) = min1 x xs