-- |applyVarSubst takes a map of substitutions and a var id
-- |and returns the substituted value if there is one, or 
-- |Var i if there isn't.
applyVarSubst :: VarsIn a => VarSubsts a -> Idx -> a
applyVarSubst subs i = case IM.lookup i subs of
  Just b -> b
  Nothing -> newVar i

-- |fromList takes a list of (var id, VarsIn) pairs
-- |and returns a VarSubsts for that list such that
-- |subs are applied from left to right (left first...)
applyVarSubst :: VarsIn a => VarSubsts a -> Idx -> a
applyVarSubst subs i = case IM.lookup i subs of
  Just b -> b
  Nothing -> newVar i

-- |fromList takes a list of (var id, VarsIn) pairs
-- |and returns a VarSubsts for that list such that
-- |subs are applied from left to right (left first...)
applyVarSubst subs i = case IM.lookup i subs of
  Just b -> b
  Nothing -> newVar i

-- |fromList takes a list of (var id, VarsIn) pairs
-- |and returns a VarSubsts for that list such that
-- |subs are applied from left to right (left first...)