Adding manual worker/wrapper transforms to Data.Map
Roman Leshchinskiy
rl at cse.unsw.edu.au
Fri Aug 20 05:13:00 EDT 2010
On 19/08/2010, at 19:38, Johan Tibell wrote:
> Hi all,
>
> I tried doing the "standard" worker/wrapper transform to some functions in Data.Map. For example, by transforming
>
> insertWith' :: Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
> insertWith' f k x m
> = insertWithKey' (\_ x' y' -> f x' y') k x m
>
> -- | Same as 'insertWithKey', but the combining function is applied strictly.
> insertWithKey' :: Ord k => (k -> a -> a -> a) -> k -> a -> Map k a -> Map k a
> insertWithKey' f kx x t0
> = case t of
> 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
> GT -> balance ky y l (insertWithKey' f kx x r)
> EQ -> let x' = f kx x y in seq x' (Bin sy kx x' l r)
Out of curiosity, is balance strict in the third argument? If not, does it make a difference if you make it strict?
Roman
More information about the Libraries
mailing list