Zulip Chat Archive
Stream: maths
Topic: list.maximum should return option
Chris Hughes (Aug 12 2019 at 06:06):
Would it be better for list.maximum to return an optional value, instead of asking for an inhabited instance. I'm working with list (fin m), where I don't know if my list is empty or not (I want to case split on this) and fin m is obviously not necessarily inhabited, and it would be a lot nicer to have an option in this situation.
Scott Morrison (Aug 12 2019 at 06:50):
I always thought requiring inhabited here was strange, but I know some people have found it convenient.
Scott Morrison (Aug 12 2019 at 06:50):
Would list.maximum.iget be significantly too painful for people who want the old behaviour?
Andrew Ashworth (Aug 12 2019 at 08:38):
Haskell's data.list.safe package requires the type to be nonempty, finite, and have an ordering as a precondition, it might have come from there.
Andrew Ashworth (Aug 12 2019 at 08:41):
of course both signatures are provided, the option kind is maximumMay :: (Foldable t, Ord a) => t a -> Maybe a...
Andrew Ashworth (Aug 12 2019 at 08:42):
so it would be useful to have both versions
Last updated: May 02 2025 at 03:31 UTC