closest :: Int -> STree Int -> Int
closest val tr
    | Nothing == suc                     = maybe (error "fuck you") id anc
    | Nothing == anc                     = maybe (error "fuck you") id suc
    | otherwise                          = clos anc suc val
  where suc                              = successor val tr
        anc                              = ancientor val tr
        clos :: Maybe Int -> Maybe Int -> Int -> Int
        clos (Just vl) (Just vr) _val    = if _val - vl > vr - _val
                                           then vr
                                           else vl
closest :: Int -> STree Int -> Int
closest val tr
    | Nothing == suc                     = maybe (error "fuck you") id anc
    | Nothing == anc                     = maybe (error "fuck you") id suc
    | otherwise                          = clos anc suc val
  where suc                              = successor val tr
        anc                              = ancientor val tr
        clos :: Maybe Int -> Maybe Int -> Int -> Int
        clos (Just vl) (Just vr) _val    = if _val - vl > vr - _val
                                           then vr
                                           else vl
closest val tr
    | Nothing == suc                     = maybe (error "fuck you") id anc
    | Nothing == anc                     = maybe (error "fuck you") id suc
    | otherwise                          = clos anc suc val
  where suc                              = successor val tr
        anc                              = ancientor val tr
        clos :: Maybe Int -> Maybe Int -> Int -> Int
        clos (Just vl) (Just vr) _val    = if _val - vl > vr - _val
                                           then vr
                                           else vl