asSeenFrom :: String -> Nat -> Context -> Either Error Term
asSeenFrom name index context =
  do t <- getTerm index context (contextLength context)
     return (addTerm (index + 1) t)
  where
    getTerm _ Star _ = Left (VarNotInContext name index context)
    getTerm index (Quant _ t c) len =
      if index == (len - 1) then return t
      else getTerm index c (len - 1)


-- | Returns the type of applying some type to another type. The third argument
-- is the object being applied.
asSeenFrom :: String -> Nat -> Context -> Either Error Term
asSeenFrom name index context =
  do t <- getTerm index context (contextLength context)
     return (addTerm (index + 1) t)
  where
    getTerm _ Star _ = Left (VarNotInContext name index context)
    getTerm index (Quant _ t c) len =
      if index == (len - 1) then return t
      else getTerm index c (len - 1)


-- | Returns the type of applying some type to another type. The third argument
-- is the object being applied.
asSeenFrom name index context =
  do t <- getTerm index context (contextLength context)
     return (addTerm (index + 1) t)
  where
    getTerm _ Star _ = Left (VarNotInContext name index context)
    getTerm index (Quant _ t c) len =
      if index == (len - 1) then return t
      else getTerm index c (len - 1)


-- | Returns the type of applying some type to another type. The third argument
-- is the object being applied.