redCase env e@(EVar x) alts     = case lookup x (eqns env) of
                                    Just e' | inline (eFlat e') -> do e' <- alphaConvert e'; redCase env e' alts
                                    Nothing -> liftM (ECase e) (redAlts env alts)
  where inline (ECon _,_)       = True
        inline (ELit _,_)       = True
        inline (EVar _, [])     = True
        inline _                = False
redCase env e@(EVar x) alts     = case lookup x (eqns env) of
                                    Just e' | inline (eFlat e') -> do e' <- alphaConvert e'; redCase env e' alts
                                    Nothing -> liftM (ECase e) (redAlts env alts)
  where inline (ECon _,_)       = True
        inline (ELit _,_)       = True
        inline (EVar _, [])     = True
        inline _                = False
redCase env e@(EVar x) alts     = case lookup x (eqns env) of
                                    Just e' | inline (eFlat e') -> do e' <- alphaConvert e'; redCase env e' alts
                                    Nothing -> liftM (ECase e) (redAlts env alts)
  where inline (ECon _,_)       = True
        inline (ELit _,_)       = True
        inline (EVar _, [])     = True
        inline _                = False