
On Tue, Nov 3, 2009 at 12:39 PM, Louis Wasserman
Hey all,
Amid the discussion of inconsistencies between Data.IntMap and Data.Map, I thought I'd throw in some more ideas. I've been working on a rather thorough generalized trie map implementation, which has done nothing if not force me to make really very generalized signatures for every method offered by Data.Map, etc. Some of these generalizations are, I think, independently useful, and I wanted to throw them out for discussion before creating a ticket.
It looks really complicated and I don't really understand any of it. So maybe as a default method for a typeclass that the datatype designer can implement, but if it were a choice between findMax and extractWithKey with some Applicative and Monoid and whatever else magic, I'd use findMax every time :) I'd be wary of putting anything difficult to describe in a default interface for a basic data type. The main functions I use with maps are forward and reverse iteration (toAscList, toDescList) and splitting, I have split2 defined which is more useful to me than Map.splitLookup: -- | Like 'Data.Map.split', except include a matched key in the above map. split2 :: (Ord k) => k -> Map.Map k a -> (Map.Map k a, Map.Map k a) And of course creating, inserting, updating, and deleting. Rarely key and value mapping. Any interface that provides those 9 functions will satisfy all needs I can think of. If they can all be implemented with extractWithKey, then great, put that in the class interface and define the rest with defaulting methods.