9 | data RedBlackSet a = E | T Color (RedBlackSet a) a (RedBlackSet a)
11 | balance : Color -> RedBlackSet a -> a -> RedBlackSet a -> RedBlackSet a
12 | balance B (T R (T R e x b) y c) z d = T R (T B e x b) y (T B c z d)
13 | balance B (T R e x (T R b y c)) z d = T R (T B e x b) y (T B c z d)
14 | balance B e x (T R (T R b y c) z d) = T R (T B e x b) y (T B c z d)
15 | balance B e x (T R b y (T R c z d)) = T R (T B e x b) y (T B c z d)
16 | balance color e x b = T color e x b
19 | Ord a => Set RedBlackSet a where
23 | member x (T _ l y r) = case compare x y of
28 | insert x s = assert_total $
let T _ l y r = ins s in T B l y r
31 | ins : RedBlackSet a -> RedBlackSet a
33 | ins s'@(T color l y r) = case compare x y of
34 | LT => balance color (ins l) y r
35 | GT => balance color l y (ins r)