This is pretty much the most concise way to write it. However, the version below will be completed even if one list is infinite (O (min (a, b)) instead of O (a + b)).
compareLengths :: [a] -> [b] -> Ordering compareLengths [ ] [ ] = EQ compareLengths (a:as) [ ] = GT compareLengths [ ] (b:bs) = LT compareLengths (a:as) (b:bs) = compareLengths as bs maxList :: [a] -> [a] -> [a] maxList ab = case compareLengths ab of GT -> a _ -> b
Also, there is no real reason to limit your function to strings only if that makes sense for arbitrary lists.
source share