import HsSyn as Hs
( HsExpr(..), HsLit(..), ArithSeqInfo(..),
- HsDoContext(..),
+ HsStmtContext(..),
Match(..), GRHSs(..), GRHS(..), HsPred(..),
- HsDecl(..), TyClDecl(..), InstDecl(..), ConDecl(..),
+ HsDecl(..), InstDecl(..), ConDecl(..),
Stmt(..), HsBinds(..), MonoBinds(..), Sig(..),
Pat(..), HsConDetails(..), HsOverLit, BangType(..),
placeHolderType, HsType(..), HsTupCon(..),
-------------------------------------------------------------------
convertToHsDecls :: [Meta.Dec] -> [HsDecl RdrName]
-convertToHsDecls ds
- = ValD (cvtdecs binds_and_sigs) : map cvt_top top_decls
- where
- (binds_and_sigs, top_decls) = partition sigOrBindP ds
+convertToHsDecls ds = map cvt_top ds
+
+cvt_top d@(Val _ _ _) = ValD (cvtd d)
+cvt_top d@(Fun _ _) = ValD (cvtd d)
+
cvt_top (Data tc tvs constrs derivs)
= TyClD (mkTyData DataType
(noContext, tconName tc, cvt_tvs tvs)
(cvt_context tys)
(HsPredTy (cvt_pred ty))
+cvt_top (Proto nm typ) = SigD (Sig (vName nm) (cvtType typ) loc0)
+
noContext = []
noExistentials = []
noFunDeps = []
cvtLit :: Lit -> HsLit
cvtLit (Char c) = HsChar (ord c)
-cvtLit (CrossStage s) = error "What do we do about crossStage constants?"
cvtp :: Meta.Pat -> Hs.Pat RdrName
cvtp (Plit l)
cvt_tvs :: [String] -> [HsTyVarBndr RdrName]
cvt_tvs tvs = map (UserTyVar . tName) tvs
-cvt_context :: Context -> HsContext RdrName
+cvt_context :: Cxt -> HsContext RdrName
cvt_context tys = map cvt_pred tys
cvt_pred :: Typ -> HsPred RdrName
other -> panic "Malformed predicate"
cvtType :: Meta.Typ -> HsType RdrName
-cvtType (Tvar nm) = HsTyVar(tName nm)
-cvtType (Tapp x y) = trans (root x [y])
- where root (Tapp a b) zs = root a (b:zs)
- root t zs = (t,zs)
- trans (Tcon (Tuple n),args) = HsTupleTy (HsTupCon Boxed n) (map cvtType args)
- trans (Tcon Arrow,[x,y]) = HsFunTy (cvtType x) (cvtType y)
- trans (Tcon List,[x]) = HsListTy (cvtType x)
- trans (Tcon (Name nm),args) = HsTyVar(tconName nm)
- trans (t,args) = panic "bad type application"
+cvtType ty = trans (root ty [])
+ where root (Tapp a b) zs = root a (cvtType b : zs)
+ root t zs = (t,zs)
+
+ trans (Tcon (Tuple n),args) | length args == n
+ = HsTupleTy (HsTupCon Boxed n) args
+ trans (Tcon Arrow, [x,y]) = HsFunTy x y
+ trans (Tcon List, [x]) = HsListTy x
+
+ trans (Tvar nm, args) = foldl HsAppTy (HsTyVar (tName nm)) args
+ trans (Tcon tc, args) = foldl HsAppTy (HsTyVar (tc_name tc)) args
+
+ tc_name (TconName nm) = tconName nm
+ tc_name Arrow = tconName "->"
+ tc_name List = tconName "[]"
+ tc_name (Tuple 0) = tconName "()"
+ tc_name (Tuple n) = tconName ("(" ++ replicate (n-1) ',' ++ ")")
split_ty_app :: Typ -> (Typ, [Typ])
split_ty_app ty = go ty []
sigP (Proto _ _) = True
sigP other = False
-sigOrBindP :: Dec -> Bool
-sigOrBindP (Proto _ _) = True
-sigOrBindP (Val _ _ _) = True
-sigOrBindP (Fun _ _) = True
-sigOrBindP other = False
-
-----------------------------------------------------------
-- some useful things