[Haskell-beginners] Get max element of a list using foldl or foldr

Andrew Bernard andrew.bernard at gmail.com
Fri Sep 25 23:59:13 UTC 2015


Hi JAMB,

If I just show an answer if defeats the purpose of the exercise, but just use max in a lambda function for the fold.

But, you need to consider what the maximum of an empty list is. Since it is hard to say what it may be, may I suggest you return a Maybe value for your function, and don’t forget to cover the case of the empty list [].

Andrew




More information about the Beginners mailing list