filter p (Bin _ x l r)
    | p x       = join x (filter p l) (filter p r)
    | otherwise = merge (filter p l) (filter p r)
filter p (Bin _ x l r)
    | p x       = join x (filter p l) (filter p r)
    | otherwise = merge (filter p l) (filter p r)
filter p (Bin _ x l r)
    | p x       = join x (filter p l) (filter p r)
    | otherwise = merge (filter p l) (filter p r)