-- | Mangles an expression.
mangleExpr :: Expr -> DebugOr Expr
mangleExpr e = case e of
  EVar (ExprName x) qt@(Unquantified t) -> EVar <$> name <*> return qt
    where
      name = ExprName <$> appendTypeSuffix x t
  EAbs bs e' -> EAbs <$> bs' <*> mangleExpr e'
    where
      bs' = traverse mangleExprBinding bs
  EApp e' es -> EApp <$> mangleExpr e' <*> traverse mangleExpr es
  EIf e1 e2 e3 -> EIf <$> mangleExpr e1 <*> mangleExpr e2 <*> mangleExpr e3
  _ -> mkSuccess e
mangleExpr :: Expr -> DebugOr Expr
mangleExpr e = case e of
  EVar (ExprName x) qt@(Unquantified t) -> EVar <$> name <*> return qt
    where
      name = ExprName <$> appendTypeSuffix x t
  EAbs bs e' -> EAbs <$> bs' <*> mangleExpr e'
    where
      bs' = traverse mangleExprBinding bs
  EApp e' es -> EApp <$> mangleExpr e' <*> traverse mangleExpr es
  EIf e1 e2 e3 -> EIf <$> mangleExpr e1 <*> mangleExpr e2 <*> mangleExpr e3
  _ -> mkSuccess e
mangleExpr e = case e of
  EVar (ExprName x) qt@(Unquantified t) -> EVar <$> name <*> return qt
    where
      name = ExprName <$> appendTypeSuffix x t
  EAbs bs e' -> EAbs <$> bs' <*> mangleExpr e'
    where
      bs' = traverse mangleExprBinding bs
  EApp e' es -> EApp <$> mangleExpr e' <*> traverse mangleExpr es
  EIf e1 e2 e3 -> EIf <$> mangleExpr e1 <*> mangleExpr e2 <*> mangleExpr e3
  _ -> mkSuccess e