sdelete targ (SNode val sz tl tr)
    | targ < val                = SNode val sz (sdelete targ tl) tr
    | targ > val                = SNode val sz tl (sdelete targ tr)
    | sisNil tl                 = tr
    | sisNil tr                 = tl
    | otherwise                 = sjoin tl tr
  where sjoin :: Ord a => STree a -> STree a -> STree a
        sjoin lt rt             = SNode sminr (ssize lt + ssize rt) lt (sdelete sminr rt)
          where (Just sminr)    = sminTree rt
sdelete targ (SNode val sz tl tr)
    | targ < val                = SNode val sz (sdelete targ tl) tr
    | targ > val                = SNode val sz tl (sdelete targ tr)
    | sisNil tl                 = tr
    | sisNil tr                 = tl
    | otherwise                 = sjoin tl tr
  where sjoin :: Ord a => STree a -> STree a -> STree a
        sjoin lt rt             = SNode sminr (ssize lt + ssize rt) lt (sdelete sminr rt)
          where (Just sminr)    = sminTree rt
sdelete targ (SNode val sz tl tr)
    | targ < val                = SNode val sz (sdelete targ tl) tr
    | targ > val                = SNode val sz tl (sdelete targ tr)
    | sisNil tl                 = tr
    | sisNil tr                 = tl
    | otherwise                 = sjoin tl tr
  where sjoin :: Ord a => STree a -> STree a -> STree a
        sjoin lt rt             = SNode sminr (ssize lt + ssize rt) lt (sdelete sminr rt)
          where (Just sminr)    = sminTree rt