Uh oh!
There was an error while loading. Please reload this page.
Add doctests for minmum/maximum related functions - #364
Conversation
I don't know about this. Semigroup instances for λ> import Data.Semigroup
λ> import qualified Data.List.NonEmpty as NE
λ> getMax $ sconcat $fmapMax$ (Arg1'a') NE.:| [Arg1'b'::ArgIntChar]
Arg1'a'
λ> getMin $ sconcat $fmapMin$ (Arg1'a') NE.:| [Arg1'b'::ArgIntChar]
Arg1'a'PS. Thank you. I did cherry pick it.
|
| -- >>> import qualified Data.Vector as V | ||
| -- >>> V.maximum $ V.fromList [2.0, 1.0] |
There was a problem hiding this comment.
Minor improvement to show that maximum for generic vectors works with other type of vectors:
| -- >>> import qualified Data.Vector as V | |
| -- >>> V.maximum $ V.fromList [2.0, 1.0] | |
| -- >>> import qualified Data.Vector.Generic as VG | |
| -- >>> import qualified Data.Vector as V | |
| -- >>> VG.maximum $ V.fromList ([2, 1] :: [Integer]) | |
| -- 2 | |
| -- >>> import qualified Data.Vector as VS | |
| -- >>> VG.maximum $ VS.fromList ([1, 2, 3] :: [Int]) | |
| -- 3 |
There was a problem hiding this comment.
I think it would be better to explain this in top-level documentation of modules. Otherwise some example will show this difference and some won't.
Shimuuar
commented
Jan 26, 2021
You're right. List functions behave in weird way: >>>minimum [Arg1'a', Arg1'b']
Arg1'a'>>> minimumBy compare [Arg1'a', Arg1'b']
Arg1'a'>>>maximum [Arg1'a', Arg1'b']
Arg1'a'>>> maximumBy compare [Arg1'a', Arg1'b']
Arg1'b'master behaves in same way, and 0.12 always returns first element. Maybe reverting changes to maximum in name of reducing breakage is better... But I don't have strong opinion here. |
Shimuuar
commented
Jan 31, 2021
I've added few more one which uses doctests: D.V.Generic.maximum, examples for maximum/minimum which involve Wrt maximum/minimum we have following choice: Don't change code in master.
Revert #180
I'm slightly lean towards keeping things as they're in master |
They assume current semantics as it's implemented in code. For minimum first tie wins, for maximum last one, I think most convincing reason to keep this semantics is that maximum/minimum pair works in exactly same way when equal values could be distinguished: >>> data F = F Int Char deriving Show >>> instance Eq F where F i _ == F j _ = i == j >>> instance Ord F where compare = comparing (\(F i _) -> i) >>> V.maximum [F 1 'a', F 1 'b'] F 1 'b' >>> V.minimum [F 1 'a', F 1 'b'] F 1 'a' As a bonus it matches behavior of list functions
Also add description and example on whether first or last tie wins
This reverts commit 2ae8a57. See discussion in haskell#362
This reverts commit 1e0052a. See discussion in haskell#362
Shimuuar
commented
Mar 5, 2021
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| -- ==== __Examples__ | ||
| -- | ||
| -- >>> import qualified Data.Vector.Unboxed as VU | ||
| -- >>> import qualified Data.Vector.Generic as VG |
There was a problem hiding this comment.
| -- >>> import qualified Data.Vector.Generic as VG |
| -- >>> VG.maximum $ VU.fromList [2.0, 1.0] | ||
| -- 2.0 |
There was a problem hiding this comment.
| -- >>> VG.maximum $ VU.fromList [2.0, 1.0] | |
| -- 2.0 |
Seems like a copy paste error, right?
There was a problem hiding this comment.
Possibly. I don't want to dig through commit to find out, Fixed
Uh oh!
There was an error while loading. Please reload this page.
Shimuuar
commented
Mar 9, 2021
I've addressed everything I thing and squashed few commits together |
@lehins@Bodigrim what's your opinion on matter?
Fixes#362
P.S. @lehins you may want to pick second commit for 0.12.2.