I tried to write a generalized maximum function similar to the one in Prelude. My first naiv approach looked like this:maximum' :: (F.Foldable a, Ord b) => a b -> Maybe bmaximum' mempty = Nothingmaximum' xs = Just $ F.foldl1 max xs
However, when I test it it always returns Nothing regardless of the input:> maximum' [1,2,3]> Nothing
Now I wonder whether it's possible to obtain the empty value of a Monoid type instance. A test function I wrote works correctly:getMempty :: (Monoid a) => a -> agetMempty _ = mempty
> getMempty [1,2,3]> []
I had already a look at these two questions but I didn't figure out how the answers solve my problem:
Write a Maximum Monoid using Maybe in Haskell
Haskell Pattern Matching on the Empty Set
How would I rewrite the maximum' function to get it to work ?
mempty, which shadows the one defined inMonoid. The second question you linked touches on similar issues. How best to accomplish your actual goal is a different matter. - C. A. McCann