Data.IntMap/IntSet inconsistencies

Twan van Laarhoven twanvl at gmail.com
Sun Nov 1 17:00:34 EST 2009


The interfaces from Data.IntMap and Data.Map are subtly different. Here are two 
issues:


1. deleteMin/Max raise an exception on empty maps/set

     > Data.Map.deleteMax Data.Map.empty
     fromList []
     > Data.IntMap.deleteMax Data.IntMap.empty
     fromList *** Exception: deleteMax: empty map has no maximal element

     > Data.Set.deleteMin Data.Set.empty
     fromList []
     > Data.IntSet.deleteMin Data.IntSet.empty
     fromList *** Exception: deleteMin: empty set has no minimal element

Proposal: Data.IntMap/IntSet.deleteMin/Max should return empty when the input is 
empty.


2. findMin/Max have a different signature

     Data.Map.findMin :: Map k a -> (k, a)
     Data.IntMap.findMin :: IntMap a -> a

The documentation of IntMap.findMin is also incorrect, it reads:

     /O(log n)/ The minimal key of the map.

While it returns the value associated with the minimal key.

Proposal: Data.IntMap.findMin/findMax should have the type  IntMap a -> (Key,a)



Twan


More information about the Libraries mailing list