[GHC] #5206: Data.Map: Add a strict version of fromListWith and fromListWithKey

GHC cvs-ghc at haskell.org
Thu May 19 10:11:11 CEST 2011


#5206: Data.Map: Add a strict version of fromListWith and fromListWithKey
---------------------------------+------------------------------------------
    Reporter:  federico_s        |       Owner:                        
        Type:  feature request   |      Status:  new                   
    Priority:  normal            |   Component:  libraries (other)     
     Version:  7.0.3             |    Keywords:  Map, strict evaluation
    Testcase:                    |   Blockedby:                        
          Os:  Unknown/Multiple  |    Blocking:                        
Architecture:  Unknown/Multiple  |     Failure:  None/Unknown          
---------------------------------+------------------------------------------
 Add to Data.Map two new functions fromListWith' and fromListWithKey'
 with strict evaluation of the combining function.


 Example use: computing the histogram of a list of values:

 hist xs = toList $ fromListWith' (+) (zip xs [1,1..])

 With the standard fromListWith there will be a stack overflow.

 How to implement it:

 fromListWithKey' f xs = foldl' ins Map.empty xs
   where
     ins t (k,x) = Map.insertWithKey' f k x t

 fromListWith' f xs = fromListWithKey' (\_ x y -> f x y) xs

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5206>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler



More information about the Glasgow-haskell-bugs mailing list