
On Thu, Aug 19, 2010 at 11:46 PM, wren ng thornton < wren@community.haskell.org> wrote:
Johan Tibell wrote:
insertWithKey' :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k a -> Map k a insertWithKey' f kx x t0 = kx `seq` go t0 where go t = case t of Tip -> singleton kx $! x Bin sy ky y l r -> case compare kx ky of LT -> balance ky y (go l) r GT -> balance ky y l (go r) EQ -> let x' = f kx x y in seq x' (Bin sy kx x' l r)
As a style issue, I'd suggest using a pattern instead of the first case:
go Tip = singleton kx $! x go (Bin sy ky y l r) =
case compare kx ky of LT -> balance ky y (go l) r GT -> balance ky y l (go r) EQ -> let x' = f kx x y in seq x' (Bin sy kx x' l r)
I'll definitely do that in the final version. -- Johan