+cvtl :: TH.Exp -> CvtM (LHsExpr RdrName)
+cvtl e = wrapL (cvt e)
+ where
+ cvt (VarE s) = do { s' <- vName s; return $ HsVar s' }
+ cvt (ConE s) = do { s' <- cName s; return $ HsVar s' }
+ cvt (LitE l)
+ | overloadedLit l = do { l' <- cvtOverLit l; return $ HsOverLit l' }
+ | otherwise = do { l' <- cvtLit l; return $ HsLit l' }
+
+ cvt (AppE x y) = do { x' <- cvtl x; y' <- cvtl y; return $ HsApp x' y' }
+ cvt (LamE ps e) = do { ps' <- cvtPats ps; e' <- cvtl e
+ ; return $ HsLam (mkMatchGroup [mkSimpleMatch ps' e']) }
+ cvt (TupE [e]) = cvt e
+ cvt (TupE es) = do { es' <- mapM cvtl es; return $ ExplicitTuple es' Boxed }
+ cvt (CondE x y z) = do { x' <- cvtl x; y' <- cvtl y; z' <- cvtl z
+ ; return $ HsIf x' y' z' }
+ cvt (LetE ds e) = do { ds' <- cvtDecs ds; e' <- cvtl e; return $ HsLet ds' e' }
+ cvt (CaseE e ms) = do { e' <- cvtl e; ms' <- mapM cvtMatch ms
+ ; return $ HsCase e' (mkMatchGroup ms') }
+ cvt (DoE ss) = cvtHsDo DoExpr ss
+ cvt (CompE ss) = cvtHsDo ListComp ss
+ cvt (ArithSeqE dd) = do { dd' <- cvtDD dd; return $ ArithSeq noPostTcExpr dd' }
+ cvt (ListE xs) = do { xs' <- mapM cvtl xs; return $ ExplicitList void xs' }
+ cvt (InfixE (Just x) s (Just y)) = do { x' <- cvtl x; s' <- cvtl s; y' <- cvtl y
+ ; e' <- returnL $ OpApp x' s' undefined y'
+ ; return $ HsPar e' }
+ cvt (InfixE Nothing s (Just y)) = do { s' <- cvtl s; y' <- cvtl y
+ ; return $ SectionR s' y' }
+ cvt (InfixE (Just x) s Nothing ) = do { x' <- cvtl x; s' <- cvtl s
+ ; return $ SectionL x' s' }
+ cvt (InfixE Nothing s Nothing ) = cvt s -- Can I indicate this is an infix thing?
+
+ cvt (SigE e t) = do { e' <- cvtl e; t' <- cvtType t
+ ; return $ ExprWithTySig e' t' }
+ cvt (RecConE c flds) = do { c' <- cNameL c
+ ; flds' <- mapM cvtFld flds
+ ; return $ RecordCon c' noPostTcExpr flds' }
+ cvt (RecUpdE e flds) = do { e' <- cvtl e
+ ; flds' <- mapM cvtFld flds
+ ; return $ RecordUpd e' flds' placeHolderType placeHolderType }
+
+cvtFld (v,e) = do { v' <- vNameL v; e' <- cvtl e; return (v',e') }
+
+cvtDD :: Range -> CvtM (ArithSeqInfo RdrName)
+cvtDD (FromR x) = do { x' <- cvtl x; return $ From x' }
+cvtDD (FromThenR x y) = do { x' <- cvtl x; y' <- cvtl y; return $ FromThen x' y' }
+cvtDD (FromToR x y) = do { x' <- cvtl x; y' <- cvtl y; return $ FromTo x' y' }
+cvtDD (FromThenToR x y z) = do { x' <- cvtl x; y' <- cvtl y; z' <- cvtl z; return $ FromThenTo x' y' z' }
+
+-------------------------------------
+-- Do notation and statements
+-------------------------------------
+
+cvtHsDo do_or_lc stmts
+ = do { stmts' <- cvtStmts stmts
+ ; let body = case last stmts' of
+ L _ (ExprStmt body _ _) -> body
+ ; return $ HsDo do_or_lc (init stmts') body void }
+
+cvtStmts = mapM cvtStmt
+
+cvtStmt :: TH.Stmt -> CvtM (Hs.LStmt RdrName)
+cvtStmt (NoBindS e) = do { e' <- cvtl e; returnL $ mkExprStmt e' }
+cvtStmt (TH.BindS p e) = do { p' <- cvtPat p; e' <- cvtl e; returnL $ mkBindStmt p' e' }
+cvtStmt (TH.LetS ds) = do { ds' <- cvtDecs ds; returnL $ LetStmt ds' }
+cvtStmt (TH.ParS dss) = do { dss' <- mapM cvt_one dss; returnL $ ParStmt dss' }
+ where
+ cvt_one ds = do { ds' <- cvtStmts ds; return (ds', undefined) }
+
+cvtMatch :: TH.Match -> CvtM (Hs.LMatch RdrName)
+cvtMatch (TH.Match p body decs)
+ = do { p' <- cvtPat p
+ ; g' <- cvtGuard body
+ ; decs' <- cvtDecs decs
+ ; returnL $ Hs.Match [p'] Nothing (GRHSs g' decs') }
+
+cvtGuard :: TH.Body -> CvtM [LGRHS RdrName]
+cvtGuard (GuardedB pairs) = mapM cvtpair pairs
+cvtGuard (NormalB e) = do { e' <- cvtl e; g' <- returnL $ GRHS [] e'; return [g'] }
+
+cvtpair :: (TH.Guard, TH.Exp) -> CvtM (LGRHS RdrName)
+cvtpair (NormalG ge,rhs) = do { ge' <- cvtl ge; rhs' <- cvtl rhs
+ ; g' <- returnL $ mkBindStmt truePat ge'
+ ; returnL $ GRHS [g'] rhs' }
+cvtpair (PatG gs,rhs) = do { gs' <- cvtStmts gs; rhs' <- cvtl rhs
+ ; returnL $ GRHS gs' rhs' }
+
+cvtOverLit :: Lit -> CvtM (HsOverLit RdrName)
+cvtOverLit (IntegerL i) = do { force i; return $ mkHsIntegral i }
+cvtOverLit (RationalL r) = do { force r; return $ mkHsFractional r }
+-- An Integer is like an an (overloaded) '3' in a Haskell source program
+-- Similarly 3.5 for fractionals