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