containsVarAlg :: forall v f . (Ord v, HasVars f v, HTraversable f) => v -> Alg f (K Bool)
containsVarAlg v t = K $ hfoldlBoundVars run local t
    where local = case isVar t of
                    Just v' -> v == v'
                    Nothing -> False
          run :: Bool -> Set v -> K Bool i -> Bool
          run acc vars (K b) = acc || (not (v `Set.member` vars) && b)

{-| This function checks whether a variable is contained in a context. -}
containsVarAlg :: forall v f . (Ord v, HasVars f v, HTraversable f) => v -> Alg f (K Bool)
containsVarAlg v t = K $ hfoldlBoundVars run local t
    where local = case isVar t of
                    Just v' -> v == v'
                    Nothing -> False
          run :: Bool -> Set v -> K Bool i -> Bool
          run acc vars (K b) = acc || (not (v `Set.member` vars) && b)

{-| This function checks whether a variable is contained in a context. -}
containsVarAlg v t = K $ hfoldlBoundVars run local t
    where local = case isVar t of
                    Just v' -> v == v'
                    Nothing -> False
          run :: Bool -> Set v -> K Bool i -> Bool
          run acc vars (K b) = acc || (not (v `Set.member` vars) && b)

{-| This function checks whether a variable is contained in a context. -}