cvs commit: fptools/libraries/base package.conf.in fptools/libraries/base/Data IntMap.hs IntSet.hs Map.hs FiniteMap.hs Set.hs

Tomasz Zielonka tomasz.zielonka at gmail.com
Mon Jan 17 03:04:01 EST 2005


On Mon, Jan 17, 2005 at 08:38:12AM +0100, Ketil Malde wrote:
> Sven Panne <Sven.Panne at aedion.de> writes:
> 
> > I must admit that I didn't follow the data structure discussion in every
> > detail, but I find something confusing: In Data.FiniteMap.addListToFM_C,
> > the combining function gets the old value as the 1st argument and the new
> > value as the 2nd one. In Data.Map.insertWithKey (and friends), this seems
> > to be the other way round, which is undocumented and *very* confusing when
> > trying to port things from FiniteMap to Map. Is there a deep reason for this?
> 
> Hmmm...I have perhaps a rather shallow reason.  When using a FiniteMap
> to collect lists of values, I think it will be more efficient to use
> (flip (++)), prepending instead of appending each new element. 

If (flip (++)) is efficient for one interface, shouldn't (++) be as efficient
for the other?

Why not use efficient catenable sequences or a ShowS trick, like here:

    groupFM :: Ord a => [(a, b)] -> FiniteMap a [b]
    groupFM l =
        mapFM (\_ -> ($ [])) $
            addListToFM_C (.) emptyFM [ (a, (b:)) | (a, b) <- l ]

PS. If anyone asks, I am strongly against introducing such artificial
    differences in library interfaces.

Best regards,
Tomasz



More information about the Libraries mailing list