[GHC] #4109: Make Data.Map.insertWith' and friends consistently force the value inserted

GHC cvs-ghc at haskell.org
Sun May 30 18:31:20 EDT 2010


#4109: Make Data.Map.insertWith' and friends consistently force the value inserted
----------------------------------+-----------------------------------------
    Reporter:  igloo              |        Owner:              
        Type:  proposal           |       Status:  new         
    Priority:  normal             |    Milestone:  Not GHC     
   Component:  libraries (other)  |      Version:  6.12.2      
    Keywords:                     |   Difficulty:              
          Os:  Unknown/Multiple   |     Testcase:              
Architecture:  Unknown/Multiple   |      Failure:  None/Unknown
----------------------------------+-----------------------------------------
 Currently, `Data.Map.insertWith'` (and friends) only force the value
 inserted when the combining function creates it:
 {{{
 Prelude Data.Map> insertWith' (+) "foo" undefined empty `seq` ()
 ()
 Prelude Data.Map> insertWith' (+) "foo" undefined (singleton "foo" 1)
 `seq` ()
 *** Exception: Prelude.undefined
 }}}
 I think it would be more consistent for it to always force it:
 {{{
 Prelude Data.Map> insertWith' (+) "foo" undefined empty `seq` ()
 *** Exception: Prelude.undefined
 Prelude Data.Map> insertWith' (+) "foo" undefined (singleton "foo" 1)
 `seq` ()
 *** Exception: Prelude.undefined
 }}}

 Patch:
 {{{
 hunk ./Data/Map.hs 460
  insertWithKey' :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k a -> Map
 k a
  insertWithKey' f kx x t
    = case t of
 -      Tip -> singleton kx x
 +      Tip -> singleton kx $! x
        Bin sy ky y l r
            -> case compare kx ky of
                 LT -> balance ky y (insertWithKey' f kx x l) r
 }}}

 Suggested discussion deadline: 14 June 2010.

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


More information about the Glasgow-haskell-bugs mailing list