-cvtDecs :: [TH.Dec] -> CvtM (HsLocalBinds RdrName)
-cvtDecs [] = return EmptyLocalBinds
-cvtDecs ds = do { (binds, sigs) <- cvtBindsAndSigs ds
- ; return (HsValBinds (ValBindsIn binds sigs)) }
-
-cvtBindsAndSigs :: [TH.Dec] -> CvtM (Bag (LHsBind RdrName), [LSig RdrName])
-cvtBindsAndSigs ds
- = do { binds' <- mapM cvtBind binds
- ; sigs' <- mapM cvtSig sigs
- ; return (listToBag binds', sigs') }
- where
- (sigs, binds) = partition is_sig ds
-
- is_sig (TH.SigD _ _) = True
- is_sig (TH.PragmaD _) = True
- is_sig _ = False
-
-cvtSig :: TH.Dec -> CvtM (LSig RdrName)
-cvtSig (TH.SigD nm ty)
- = do { nm' <- vNameL nm
- ; ty' <- cvtType ty
- ; returnL (Hs.TypeSig nm' ty')
- }
-cvtSig (TH.PragmaD prag)
- = do { prag' <- cvtPragmaD prag
- ; returnL prag'
- }
-cvtSig _ = panic "Convert.cvtSig: Signature expected"
-
-cvtBind :: TH.Dec -> CvtM (LHsBind RdrName)
--- Used only for declarations in a 'let/where' clause,
--- not for top level decls
-cvtBind (TH.ValD (TH.VarP s) body ds)
- = do { s' <- vNameL s
- ; cl' <- cvtClause (Clause [] body ds)
- ; returnL $ mkFunBind s' [cl'] }
-
-cvtBind (TH.FunD nm cls)
- | null cls
- = failWith (ptext (sLit "Function binding for")
- <+> quotes (text (TH.pprint nm))
- <+> ptext (sLit "has no equations"))