Proposal: Make Data.Map.insertWith' and friends consistently force the value inserted
Hi all, 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 Ticket: http://hackage.haskell.org/trac/ghc/ticket/4109 Suggested discussion deadline: 14 June 2010. Thanks Ian
On Sun, May 30, 2010 at 11:34:47PM +0100, Ian Lynagh wrote:
Hi all,
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
The current behaviour is unexpected. +1 for the patch. -- Felipe.
+1 Sent from my iPhone On May 30, 2010, at 8:51 PM, Felipe Lessa <felipe.lessa@gmail.com> wrote:
On Sun, May 30, 2010 at 11:34:47PM +0100, Ian Lynagh wrote:
Hi all,
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
The current behaviour is unexpected.
+1 for the patch.
-- Felipe. _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
+1 from here as well. The existing behaviour is not consistent with what I would expect insertWith' to produce. On Mon, May 31, 2010 at 3:08 AM, Edward Kmett <ekmett@gmail.com> wrote:
+1
Sent from my iPhone
On May 30, 2010, at 8:51 PM, Felipe Lessa <felipe.lessa@gmail.com> wrote:
On Sun, May 30, 2010 at 11:34:47PM +0100, Ian Lynagh wrote:
Hi all,
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
The current behaviour is unexpected.
+1 for the patch.
-- Felipe. _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
-- J.
On Sun, 30 May 2010 23:34:47 +0100, Ian Lynagh <igloo@earth.li> wrote:
Hi all,
Currently, Data.Map.insertWith' (and friends) only force the value inserted when the combining function creates it:
+1 for this patch. -- Nicolas Pouillard http://nicolaspouillard.fr
+1 (Although a user can seq the value herself before calling insertWith'...) Regards, Bas P.S. I just noticed that Data.IntMap doesn't provide the strict insertWith' and insertWithKey' like Data.Map does. That seems to be a bit inconsistent. On Mon, May 31, 2010 at 12:34 AM, Ian Lynagh <igloo@earth.li> wrote:
Hi all,
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
Ticket: http://hackage.haskell.org/trac/ghc/ticket/4109
Suggested discussion deadline: 14 June 2010.
Thanks Ian
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
participants (6)
-
Bas van Dijk -
Edward Kmett -
Felipe Lessa -
Ian Lynagh -
Jesper Louis Andersen -
Nicolas Pouillard