equations gamma0 term@(Appl term1 term2) = do
  (gamma1, t1, eq1) <- equations gamma0 term1
  (gamma2, t2, eq2) <- equations gamma0 term2
  freshT <- newTypeVar
  return (uniteUnique gamma1 gamma2,
          freshT,
          insert (TEVar t1, TEArrow (TEVar t2) (TEVar freshT))
            (eq1 `union` eq2 `union` (equateContexts gamma1 gamma2)))

  -- Make union of two contexts, dropping possible duplicates
equations gamma0 term@(Appl term1 term2) = do
  (gamma1, t1, eq1) <- equations gamma0 term1
  (gamma2, t2, eq2) <- equations gamma0 term2
  freshT <- newTypeVar
  return (uniteUnique gamma1 gamma2,
          freshT,
          insert (TEVar t1, TEArrow (TEVar t2) (TEVar freshT))
            (eq1 `union` eq2 `union` (equateContexts gamma1 gamma2)))

  -- Make union of two contexts, dropping possible duplicates
equations gamma0 term@(Appl term1 term2) = do
  (gamma1, t1, eq1) <- equations gamma0 term1
  (gamma2, t2, eq2) <- equations gamma0 term2
  freshT <- newTypeVar
  return (uniteUnique gamma1 gamma2,
          freshT,
          insert (TEVar t1, TEArrow (TEVar t2) (TEVar freshT))
            (eq1 `union` eq2 `union` (equateContexts gamma1 gamma2)))

  -- Make union of two contexts, dropping possible duplicates