Adding manual worker/wrapper transforms to Data.Map

Johan Tibell johan.tibell at gmail.com
Fri Aug 20 05:20:05 EDT 2010


On Fri, Aug 20, 2010 at 11:13 AM, Roman Leshchinskiy <rl at cse.unsw.edu.au>wrote:

> 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?
>

I haven't checked since Milan completely rewrote balance but hasn't
integrated his changes yet. I'll have a look at balance once those changes
are in.

-- Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/libraries/attachments/20100820/5d2ac039/attachment-0001.html


More information about the Libraries mailing list