Adding manual worker/wrapper transforms to Data.Map

Johan Tibell johan.tibell at gmail.com
Fri Aug 20 04:36:27 EDT 2010


On Thu, Aug 19, 2010 at 11:46 PM, wren ng thornton <
wren at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/libraries/attachments/20100820/db512031/attachment.html


More information about the Libraries mailing list