WILCC2NZDLTXRZADOLY2I4O2UP4BC7ZA7G7PFWXZAXUNRSBUS4AQC
switchColor (Node Black l v r) = Node Red l v r
switchColor (Node Red l v r) = Node Black l v r
switchColor n = n
nodeDirection :: TreeZipper a -> Direction
nodeDirection = fst . last . fst
parent :: TreeZipper a -> TreeZipper a
parent = up
sibling :: TreeZipper a -> TreeZipper a
sibling node = case nodeDirection node of
L -> right . parent $ node
R -> left . parent $ node
-- Maybe this is a candidate for GADTS?
data Case a
distantNephew :: TreeZipper a -> TreeZipper a
distantNephew z = case nodeDirection z of
L -> right . sibling $ z
R -> left . sibling $ z
closeNephew :: TreeZipper a -> TreeZipper a
closeNephew z = case nodeDirection z of
L -> left . sibling $ z
R -> right . sibling $ z
colorOf :: RedBlackTree a -> Color
colorOf Leaf = Black
colorOf (Node c _ _ _) = c
data Case
[Red, Black, Black, Black] -> D4 (snd $ parent zipper) (snd $ sibling zipper)
where
colorOf Leaf = Black
colorOf (Node c _ _ _) = c
ourDirection = fst . last . fst $ zipper
sibling z = case ourDirection of
L -> right . parent $ z
R -> left . parent $ z
parent = up
distant_nephew z = case ourDirection of
L -> right . sibling $ z
R -> left . sibling $ z
close_nephew z = case ourDirection of
L -> left . sibling $ z
R -> right . sibling $ z
[Red, Black, Black, Black] -> D4