redEta env te (EAp e es)        = do es <- mapM (redExp env') es
                                     e <- redExp env' e
                                     if okEta e && es == map EVar xs then
                                        return e
                                      else do
                                        liftM (ELam te) (redApp env' e es)
  where okEta (ECon _)          = False
        okEta (EVar (Prim _ _)) = False
        okEta e                 = null (evars e `intersect` xs)
        env'                    = addArgs env (dom te)
        xs                      = dom te
redEta env te (EAp e es)        = do es <- mapM (redExp env') es
                                     e <- redExp env' e
                                     if okEta e && es == map EVar xs then
                                        return e
                                      else do
                                        liftM (ELam te) (redApp env' e es)
  where okEta (ECon _)          = False
        okEta (EVar (Prim _ _)) = False
        okEta e                 = null (evars e `intersect` xs)
        env'                    = addArgs env (dom te)
        xs                      = dom te
redEta env te (EAp e es)        = do es <- mapM (redExp env') es
                                     e <- redExp env' e
                                     if okEta e && es == map EVar xs then
                                        return e
                                      else do
                                        liftM (ELam te) (redApp env' e es)
  where okEta (ECon _)          = False
        okEta (EVar (Prim _ _)) = False
        okEta e                 = null (evars e `intersect` xs)
        env'                    = addArgs env (dom te)
        xs                      = dom te