4 ms·
So if I got that right, the future best practice will be to use foldMap/foldMap' on all data structures unless you require a particular associativity.
by im3w1l 7y ago
So if I got that right, the future best practice will be to use foldMap/foldMap' on all data structures unless you require a particular associativity.
- MaxGabriel 7y agoThat doesn’t sound like the correct reading to me, because foldMap and foldl/foldr have different type signatures https://www.stackage.org/haddock/lts-15.4/base-4.13.0.0/Prelude.html#v:foldMap https://www.stackage.org/haddock/lts-15.4/base-4.13.0.0/Prel...
- im3w1l 7y agoYeah, but they solve basically the same problem. As I mentioned, foldMap requires associativity. Per your link I guess it also requires existence of a neutral element (whereas foldr instead makes you specify a starting element).
- solomonb 7y agoOnly if you have a valid Monoid instance to work with..