Hello,
I think that "dead end #3" is the right choice, and keep Foldable etc. in their own modules. We have a module system, we should use it. In general, I think if we are to "burn bridges" it should be by moving things out of the Prelude, not adding more abstractions there.
For the sake of concreteness, here are some of the things I don't like about the current design:
(e.g., why are 'sum' and 'product' there??).
Camp 2)sum = foldl (+) 0is the implementation that is in the Haskell Report.This implementation is actually pretty much maximally bad for all usecases. It has uses foldl so it leaks all sorts of memory while building up the structure that it finally folds.
sum = foldl' (+) 0
is the implementation that folks like Duncan would rather see.This kills most of the space and performance problems with the standard implementation, but switching could introduce bottoms in existing programs.
Camp 3)
sum = getSum . foldMap sum
is the implementation that ensures that it doesn't destroy the asymptotics of the number of uses of 'mappend' in foldMap.
The right container can readily fold 2^20th a's with 20 mappends.
The best the camp 2 solution can do is still 1 million steps, but at least those steps aren't randomly leaking space.
Similarly consider maximum from the Report:The downside of this is that this implementation can use more stack in the cases where ghc was smart enough to monomorphize the original Prelude solution to a number type where it could figure out via strictness that it could do an efficient left fold.
maximum, minimum :: (Ord a) => [a] -> amaximum [] = error "Prelude.maximum: empty list"maximum xs = foldl1 max xs
-- | The largest element of a non-empty structure.
maximum :: (Foldable t, Ord a) => t a -> amaximum = foldr1 max
- the state of Data.List: I generally prefer that, when possible, a datatype should provide non-overloaded access to its functionality, and in addition, there can be instances to expose the same functionality via an overloaded API.
Of course, I can generally work around all of those, so not a big deal. However, it'd be nice if we could come up with a design that, more or less, the whole community thinks is a good one.