? patch
? base/Data/fix.patch
Index: base/Data/IntMap.hs
===================================================================
RCS file: /cvs/fptools/libraries/base/Data/IntMap.hs,v
retrieving revision 1.17
diff -r1.17 IntMap.hs
806a807,820
>       Bin p m l r 
>           | m < 0 -> (if k >= 0 -- handle negative numbers.
>                       then let (lt,gt) = split' k l in (union r lt, gt)
>                       else let (lt,gt) = split' k r in (lt, union gt l))
>           | otherwise   -> split' k t
>       Tip ky y 
>         | k>ky      -> (t,Nil)
>         | k<ky      -> (Nil,t)
>         | otherwise -> (Nil,Nil)
>       Nil -> (Nil,Nil)
> 
> split' :: Key -> IntMap a -> (IntMap a,IntMap a)
> split' k t
>   = case t of
822a837,850
>           | m < 0 -> (if k >= 0 -- handle negative numbers.
>                       then let (lt,found,gt) = splitLookup' k l in (union r lt,found, gt)
>                       else let (lt,found,gt) = splitLookup' k r in (lt,found, union gt l))
>           | otherwise   -> splitLookup' k t
>       Tip ky y 
>         | k>ky      -> (t,Nothing,Nil)
>         | k<ky      -> (Nil,Nothing,t)
>         | otherwise -> (Nil,Just y,Nil)
>       Nil -> (Nil,Nothing,Nil)
> 
> splitLookup' :: Key -> IntMap a -> (IntMap a,Maybe a,IntMap a)
> splitLookup' k t
>   = case t of
>       Bin p m l r
858c886,894
<       Bin p m l r -> foldr f (foldr f z r) l
---
>       Bin 0 m l r | m < 0 -> foldr' f (foldr' f z l) r  -- put negative numbers before.
>       Bin _ _ _ _ -> foldr' f z t
>       Tip k x     -> f k x z
>       Nil         -> z
> 
> foldr' :: (Key -> a -> b -> b) -> b -> IntMap a -> b
> foldr' f z t
>   = case t of
>       Bin p m l r -> foldr' f (foldr' f z r) l
861a898,899
> 
> 
Index: base/Data/IntSet.hs
===================================================================
RCS file: /cvs/fptools/libraries/base/Data/IntSet.hs,v
retrieving revision 1.16
diff -r1.16 IntSet.hs
464,465c464,481
<         | zero x m  -> let (lt,gt) = split x l in (lt,union gt r)
<         | otherwise -> let (lt,gt) = split x r in (union l lt,gt)
---
>         | m < 0       -> if x >= 0 then let (lt,gt) = split' x l in (union r lt, gt)
>                                    else let (lt,gt) = split' x r in (lt, union gt l)
>                                    -- handle negative numbers.
>         | otherwise   -> split' x t
>       Tip y 
>         | x>y         -> (t,Nil)
>         | x<y         -> (Nil,t)
>         | otherwise   -> (Nil,Nil)
>       Nil             -> (Nil, Nil)
> 
> split' :: Int -> IntSet -> (IntSet,IntSet)
> split' x t
>   = case t of
>       Bin p m l r
>         | match x p m -> if zero x m then let (lt,gt) = split' x l in (lt,union gt r)
>                                      else let (lt,gt) = split' x r in (union l lt,gt)
>         | otherwise   -> if x < p then (Nil, t)
>                                   else (t, Nil)
478,479c494,511
<         | zero x m  -> let (lt,found,gt) = splitMember x l in (lt,found,union gt r)
<         | otherwise -> let (lt,found,gt) = splitMember x r in (union l lt,found,gt)
---
>         | m < 0       -> if x >= 0 then let (lt,found,gt) = splitMember' x l in (union r lt, found, gt)
>                                    else let (lt,found,gt) = splitMember' x r in (lt, found, union gt l)
>                                    -- handle negative numbers.
>         | otherwise   -> splitMember' x t
>       Tip y 
>         | x>y       -> (t,False,Nil)
>         | x<y       -> (Nil,False,t)
>         | otherwise -> (Nil,True,Nil)
>       Nil -> (Nil,False,Nil)
> 
> splitMember' :: Int -> IntSet -> (IntSet,Bool,IntSet)
> splitMember' x t
>   = case t of
>       Bin p m l r
>          | match x p m ->  if zero x m then let (lt,found,gt) = splitMember x l in (lt,found,union gt r)
>                                        else let (lt,found,gt) = splitMember x r in (union l lt,found,gt)
>          | otherwise   -> if x < p then (Nil, False, t)
>                                    else (t, False, Nil)
508c540,545
<   = foldr f z t
---
>   = case t of
>       Bin 0 m l r | m < 0 -> foldr f (foldr f z l) r  
>       -- put negative numbers before.
>       Bin p m l r -> foldr f z t
>       Tip x       -> f x z
>       Nil         -> z
535,537c572
< toAscList t   
<   = -- NOTE: the following algorithm only works for big-endian trees
<     let (pos,neg) = span (>=0) (foldr (:) [] t) in neg ++ pos
---
> toAscList t = toList t









