1 -----------------------------------------------------------------------------
3 -- (c) The University of Glasgow 2006
5 -- The purpose of this module is to transform an HsExpr into a CoreExpr which
6 -- when evaluated, returns a (Meta.Q Meta.Exp) computation analogous to the
7 -- input HsExpr. We do this in the DsM monad, which supplies access to
8 -- CoreExpr's of the "smart constructors" of the Meta.Exp datatype.
10 -- It also defines a bunch of knownKeyNames, in the same way as is done
11 -- in prelude/PrelNames. It's much more convenient to do it here, becuase
12 -- otherwise we have to recompile PrelNames whenever we add a Name, which is
13 -- a Royal Pain (triggers other recompilation).
14 -----------------------------------------------------------------------------
17 -- The above warning supression flag is a temporary kludge.
18 -- While working on this module you are encouraged to remove it and fix
19 -- any warnings in the module. See
20 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
23 module DsMeta( dsBracket,
24 templateHaskellNames, qTyConName, nameTyConName,
25 liftName, expQTyConName, patQTyConName, decQTyConName, typeQTyConName,
26 decTyConName, typeTyConName, mkNameG_dName, mkNameG_vName, mkNameG_tcName,
27 quoteExpName, quotePatName
30 import {-# SOURCE #-} DsExpr ( dsExpr )
36 import qualified Language.Haskell.TH as TH
41 -- To avoid clashes with DsMeta.varName we must make a local alias for
42 -- OccName.varName we do this by removing varName from the import of
43 -- OccName above, making a qualified instance of OccName and using
44 -- OccNameAlias.varName where varName ws previously used in this file.
45 import qualified OccName
69 -----------------------------------------------------------------------------
70 dsBracket :: HsBracket Name -> [PendingSplice] -> DsM CoreExpr
71 -- Returns a CoreExpr of type TH.ExpQ
72 -- The quoted thing is parameterised over Name, even though it has
73 -- been type checked. We don't want all those type decorations!
75 dsBracket brack splices
76 = dsExtendMetaEnv new_bit (do_brack brack)
78 new_bit = mkNameEnv [(n, Splice (unLoc e)) | (n,e) <- splices]
80 do_brack (VarBr n) = do { MkC e1 <- lookupOcc n ; return e1 }
81 do_brack (ExpBr e) = do { MkC e1 <- repLE e ; return e1 }
82 do_brack (PatBr p) = do { MkC p1 <- repLP p ; return p1 }
83 do_brack (TypBr t) = do { MkC t1 <- repLTy t ; return t1 }
84 do_brack (DecBr ds) = do { MkC ds1 <- repTopDs ds ; return ds1 }
86 {- -------------- Examples --------------------
90 gensym (unpackString "x"#) `bindQ` \ x1::String ->
91 lam (pvar x1) (var x1)
94 [| \x -> $(f [| x |]) |]
96 gensym (unpackString "x"#) `bindQ` \ x1::String ->
97 lam (pvar x1) (f (var x1))
101 -------------------------------------------------------
103 -------------------------------------------------------
105 repTopDs :: HsGroup Name -> DsM (Core (TH.Q [TH.Dec]))
107 = do { let { bndrs = map unLoc (groupBinders group) } ;
108 ss <- mkGenSyms bndrs ;
110 -- Bind all the names mainly to avoid repeated use of explicit strings.
112 -- do { t :: String <- genSym "T" ;
113 -- return (Data t [] ...more t's... }
114 -- The other important reason is that the output must mention
115 -- only "T", not "Foo:T" where Foo is the current module
118 decls <- addBinds ss (do {
119 val_ds <- rep_val_binds (hs_valds group) ;
120 tycl_ds <- mapM repTyClD (hs_tyclds group) ;
121 inst_ds <- mapM repInstD' (hs_instds group) ;
122 for_ds <- mapM repForD (hs_fords group) ;
124 return (de_loc $ sort_by_loc $ val_ds ++ catMaybes tycl_ds ++ inst_ds ++ for_ds) }) ;
126 decl_ty <- lookupType decQTyConName ;
127 let { core_list = coreList' decl_ty decls } ;
129 dec_ty <- lookupType decTyConName ;
130 q_decs <- repSequenceQ dec_ty core_list ;
132 wrapNongenSyms ss q_decs
133 -- Do *not* gensym top-level binders
136 groupBinders (HsGroup { hs_valds = val_decls, hs_tyclds = tycl_decls,
137 hs_fords = foreign_decls })
138 -- Collect the binders of a Group
139 = collectHsValBinders val_decls ++
140 [n | d <- tycl_decls, n <- tyClDeclNames (unLoc d)] ++
141 [n | L _ (ForeignImport n _ _) <- foreign_decls]
144 {- Note [Binders and occurrences]
145 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146 When we desugar [d| data T = MkT |]
148 Data "T" [] [Con "MkT" []] []
150 Data "Foo:T" [] [Con "Foo:MkT" []] []
151 That is, the new data decl should fit into whatever new module it is
152 asked to fit in. We do *not* clone, though; no need for this:
159 then we must desugar to
160 foo = Data "Foo:T" [] [Con "Foo:MkT" []] []
162 So in repTopDs we bring the binders into scope with mkGenSyms and addBinds.
163 And we use lookupOcc, rather than lookupBinder
164 in repTyClD and repC.
168 repTyClD :: LTyClDecl Name -> DsM (Maybe (SrcSpan, Core TH.DecQ))
170 repTyClD (L loc (TyData { tcdND = DataType, tcdCtxt = cxt,
171 tcdLName = tc, tcdTyVars = tvs,
172 tcdCons = cons, tcdDerivs = mb_derivs }))
173 = do { tc1 <- lookupLOcc tc ; -- See note [Binders and occurrences]
174 dec <- addTyVarBinds tvs $ \bndrs -> do {
175 cxt1 <- repLContext cxt ;
176 cons1 <- mapM repC cons ;
177 cons2 <- coreList conQTyConName cons1 ;
178 derivs1 <- repDerivs mb_derivs ;
179 bndrs1 <- coreList nameTyConName bndrs ;
180 repData cxt1 tc1 bndrs1 cons2 derivs1 } ;
181 return $ Just (loc, dec) }
183 repTyClD (L loc (TyData { tcdND = NewType, tcdCtxt = cxt,
184 tcdLName = tc, tcdTyVars = tvs,
185 tcdCons = [con], tcdDerivs = mb_derivs }))
186 = do { tc1 <- lookupLOcc tc ; -- See note [Binders and occurrences]
187 dec <- addTyVarBinds tvs $ \bndrs -> do {
188 cxt1 <- repLContext cxt ;
190 derivs1 <- repDerivs mb_derivs ;
191 bndrs1 <- coreList nameTyConName bndrs ;
192 repNewtype cxt1 tc1 bndrs1 con1 derivs1 } ;
193 return $ Just (loc, dec) }
195 repTyClD (L loc (TySynonym { tcdLName = tc, tcdTyVars = tvs, tcdSynRhs = ty }))
196 = do { tc1 <- lookupLOcc tc ; -- See note [Binders and occurrences]
197 dec <- addTyVarBinds tvs $ \bndrs -> do {
199 bndrs1 <- coreList nameTyConName bndrs ;
200 repTySyn tc1 bndrs1 ty1 } ;
201 return (Just (loc, dec)) }
203 repTyClD (L loc (ClassDecl { tcdCtxt = cxt, tcdLName = cls,
206 tcdSigs = sigs, tcdMeths = meth_binds }))
207 = do { cls1 <- lookupLOcc cls ; -- See note [Binders and occurrences]
208 dec <- addTyVarBinds tvs $ \bndrs -> do {
209 cxt1 <- repLContext cxt ;
210 sigs1 <- rep_sigs sigs ;
211 binds1 <- rep_binds meth_binds ;
212 fds1 <- repLFunDeps fds;
213 decls1 <- coreList decQTyConName (sigs1 ++ binds1) ;
214 bndrs1 <- coreList nameTyConName bndrs ;
215 repClass cxt1 cls1 bndrs1 fds1 decls1 } ;
216 return $ Just (loc, dec) }
219 repTyClD (L loc d) = putSrcSpanDs loc $
220 do { warnDs (hang ds_msg 4 (ppr d))
225 repLFunDeps :: [Located (FunDep Name)] -> DsM (Core [TH.FunDep])
226 repLFunDeps fds = do fds' <- mapM repLFunDep fds
227 fdList <- coreList funDepTyConName fds'
230 repLFunDep :: Located (FunDep Name) -> DsM (Core TH.FunDep)
231 repLFunDep (L _ (xs, ys)) = do xs' <- mapM lookupBinder xs
232 ys' <- mapM lookupBinder ys
233 xs_list <- coreList nameTyConName xs'
234 ys_list <- coreList nameTyConName ys'
235 repFunDep xs_list ys_list
237 repInstD' (L loc (InstDecl ty binds _ _)) -- Ignore user pragmas for now
238 = do { i <- addTyVarBinds tvs $ \tv_bndrs ->
239 -- We must bring the type variables into scope, so their occurrences
240 -- don't fail, even though the binders don't appear in the resulting
242 do { cxt1 <- repContext cxt
243 ; inst_ty1 <- repPred (HsClassP cls tys)
244 ; ss <- mkGenSyms (collectHsBindBinders binds)
245 ; binds1 <- addBinds ss (rep_binds binds)
246 ; decls1 <- coreList decQTyConName binds1
247 ; decls2 <- wrapNongenSyms ss decls1
248 -- wrapNonGenSyms: do not clone the class op names!
249 -- They must be called 'op' etc, not 'op34'
250 ; repInst cxt1 inst_ty1 decls2 }
254 (tvs, cxt, cls, tys) = splitHsInstDeclTy (unLoc ty)
256 repForD :: Located (ForeignDecl Name) -> DsM (SrcSpan, Core TH.DecQ)
257 repForD (L loc (ForeignImport name typ (CImport cc s ch cn cis)))
258 = do MkC name' <- lookupLOcc name
259 MkC typ' <- repLTy typ
260 MkC cc' <- repCCallConv cc
261 MkC s' <- repSafety s
262 cis' <- conv_cimportspec cis
263 MkC str <- coreStringLit $ static
264 ++ unpackFS ch ++ " "
265 ++ unpackFS cn ++ " "
267 dec <- rep2 forImpDName [cc', s', str, name', typ']
270 conv_cimportspec (CLabel cls) = notHandled "Foreign label" (doubleQuotes (ppr cls))
271 conv_cimportspec (CFunction DynamicTarget) = return "dynamic"
272 conv_cimportspec (CFunction (StaticTarget fs)) = return (unpackFS fs)
273 conv_cimportspec CWrapper = return "wrapper"
275 CFunction (StaticTarget _) -> "static "
277 repForD decl = notHandled "Foreign declaration" (ppr decl)
279 repCCallConv :: CCallConv -> DsM (Core TH.Callconv)
280 repCCallConv CCallConv = rep2 cCallName []
281 repCCallConv StdCallConv = rep2 stdCallName []
283 repSafety :: Safety -> DsM (Core TH.Safety)
284 repSafety PlayRisky = rep2 unsafeName []
285 repSafety (PlaySafe False) = rep2 safeName []
286 repSafety (PlaySafe True) = rep2 threadsafeName []
288 ds_msg = ptext (sLit "Cannot desugar this Template Haskell declaration:")
290 -------------------------------------------------------
292 -------------------------------------------------------
294 repC :: LConDecl Name -> DsM (Core TH.ConQ)
295 repC (L loc (ConDecl con expl [] (L _ []) details ResTyH98 _))
296 = do { con1 <- lookupLOcc con ; -- See note [Binders and occurrences]
297 repConstr con1 details }
298 repC (L loc (ConDecl con expl tvs (L cloc ctxt) details ResTyH98 doc))
299 = do { addTyVarBinds tvs $ \bndrs -> do {
300 c' <- repC (L loc (ConDecl con expl [] (L cloc []) details ResTyH98 doc));
301 ctxt' <- repContext ctxt;
302 bndrs' <- coreList nameTyConName bndrs;
303 rep2 forallCName [unC bndrs', unC ctxt', unC c']
306 repC (L loc con_decl) -- GADTs
308 notHandled "GADT declaration" (ppr con_decl)
310 repBangTy :: LBangType Name -> DsM (Core (TH.StrictTypeQ))
314 rep2 strictTypeName [s, t]
316 (str, ty') = case ty of
317 L _ (HsBangTy _ ty) -> (isStrictName, ty)
318 other -> (notStrictName, ty)
320 -------------------------------------------------------
322 -------------------------------------------------------
324 repDerivs :: Maybe [LHsType Name] -> DsM (Core [TH.Name])
325 repDerivs Nothing = coreList nameTyConName []
326 repDerivs (Just ctxt)
327 = do { strs <- mapM rep_deriv ctxt ;
328 coreList nameTyConName strs }
330 rep_deriv :: LHsType Name -> DsM (Core TH.Name)
331 -- Deriving clauses must have the simple H98 form
332 rep_deriv (L _ (HsPredTy (HsClassP cls []))) = lookupOcc cls
333 rep_deriv other = notHandled "Non-H98 deriving clause" (ppr other)
336 -------------------------------------------------------
337 -- Signatures in a class decl, or a group of bindings
338 -------------------------------------------------------
340 rep_sigs :: [LSig Name] -> DsM [Core TH.DecQ]
341 rep_sigs sigs = do locs_cores <- rep_sigs' sigs
342 return $ de_loc $ sort_by_loc locs_cores
344 rep_sigs' :: [LSig Name] -> DsM [(SrcSpan, Core TH.DecQ)]
345 -- We silently ignore ones we don't recognise
346 rep_sigs' sigs = do { sigs1 <- mapM rep_sig sigs ;
347 return (concat sigs1) }
349 rep_sig :: LSig Name -> DsM [(SrcSpan, Core TH.DecQ)]
351 -- Empty => Too hard, signature ignored
352 rep_sig (L loc (TypeSig nm ty)) = rep_proto nm ty loc
353 rep_sig other = return []
355 rep_proto :: Located Name -> LHsType Name -> SrcSpan -> DsM [(SrcSpan, Core TH.DecQ)]
356 rep_proto nm ty loc = do { nm1 <- lookupLOcc nm ;
358 sig <- repProto nm1 ty1 ;
359 return [(loc, sig)] }
362 -------------------------------------------------------
364 -------------------------------------------------------
366 -- gensym a list of type variables and enter them into the meta environment;
367 -- the computations passed as the second argument is executed in that extended
368 -- meta environment and gets the *new* names on Core-level as an argument
370 addTyVarBinds :: [LHsTyVarBndr Name] -- the binders to be added
371 -> ([Core TH.Name] -> DsM (Core (TH.Q a))) -- action in the ext env
372 -> DsM (Core (TH.Q a))
373 addTyVarBinds tvs m =
375 let names = map (hsTyVarName.unLoc) tvs
376 freshNames <- mkGenSyms names
377 term <- addBinds freshNames $ do
378 bndrs <- mapM lookupBinder names
380 wrapGenSyns freshNames term
382 -- represent a type context
384 repLContext :: LHsContext Name -> DsM (Core TH.CxtQ)
385 repLContext (L _ ctxt) = repContext ctxt
387 repContext :: HsContext Name -> DsM (Core TH.CxtQ)
389 preds <- mapM repLPred ctxt
390 predList <- coreList typeQTyConName preds
393 -- represent a type predicate
395 repLPred :: LHsPred Name -> DsM (Core TH.TypeQ)
396 repLPred (L _ p) = repPred p
398 repPred :: HsPred Name -> DsM (Core TH.TypeQ)
399 repPred (HsClassP cls tys) = do
400 tcon <- repTy (HsTyVar cls)
403 repPred p@(HsEqualP _ _) = notHandled "Equational constraint" (ppr p)
404 repPred p@(HsIParam _ _) = notHandled "Implicit parameter constraint" (ppr p)
406 -- yield the representation of a list of types
408 repLTys :: [LHsType Name] -> DsM [Core TH.TypeQ]
409 repLTys tys = mapM repLTy tys
413 repLTy :: LHsType Name -> DsM (Core TH.TypeQ)
414 repLTy (L _ ty) = repTy ty
416 repTy :: HsType Name -> DsM (Core TH.TypeQ)
417 repTy (HsForAllTy _ tvs ctxt ty) =
418 addTyVarBinds tvs $ \bndrs -> do
419 ctxt1 <- repLContext ctxt
421 bndrs1 <- coreList nameTyConName bndrs
422 repTForall bndrs1 ctxt1 ty1
425 | isTvOcc (nameOccName n) = do
431 repTy (HsAppTy f a) = do
435 repTy (HsFunTy f a) = do
438 tcon <- repArrowTyCon
439 repTapps tcon [f1, a1]
440 repTy (HsListTy t) = do
444 repTy (HsPArrTy t) = do
446 tcon <- repTy (HsTyVar (tyConName parrTyCon))
448 repTy (HsTupleTy tc tys) = do
450 tcon <- repTupleTyCon (length tys)
452 repTy (HsOpTy ty1 n ty2) = repLTy ((nlHsTyVar (unLoc n) `nlHsAppTy` ty1)
454 repTy (HsParTy t) = repLTy t
455 repTy (HsPredTy pred) = repPred pred
456 repTy ty@(HsNumTy _) = notHandled "Number types (for generics)" (ppr ty)
457 repTy ty = notHandled "Exotic form of type" (ppr ty)
460 -----------------------------------------------------------------------------
462 -----------------------------------------------------------------------------
464 repLEs :: [LHsExpr Name] -> DsM (Core [TH.ExpQ])
465 repLEs es = do { es' <- mapM repLE es ;
466 coreList expQTyConName es' }
468 -- FIXME: some of these panics should be converted into proper error messages
469 -- unless we can make sure that constructs, which are plainly not
470 -- supported in TH already lead to error messages at an earlier stage
471 repLE :: LHsExpr Name -> DsM (Core TH.ExpQ)
472 repLE (L loc e) = putSrcSpanDs loc (repE e)
474 repE :: HsExpr Name -> DsM (Core TH.ExpQ)
476 do { mb_val <- dsLookupMetaEnv x
478 Nothing -> do { str <- globalVar x
479 ; repVarOrCon x str }
480 Just (Bound y) -> repVarOrCon x (coreVar y)
481 Just (Splice e) -> do { e' <- dsExpr e
482 ; return (MkC e') } }
483 repE e@(HsIPVar x) = notHandled "Implicit parameters" (ppr e)
485 -- Remember, we're desugaring renamer output here, so
486 -- HsOverlit can definitely occur
487 repE (HsOverLit l) = do { a <- repOverloadedLiteral l; repLit a }
488 repE (HsLit l) = do { a <- repLiteral l; repLit a }
489 repE (HsLam (MatchGroup [m] _)) = repLambda m
490 repE (HsApp x y) = do {a <- repLE x; b <- repLE y; repApp a b}
492 repE (OpApp e1 op fix e2) =
493 do { arg1 <- repLE e1;
496 repInfixApp arg1 the_op arg2 }
497 repE (NegApp x nm) = do
499 negateVar <- lookupOcc negateName >>= repVar
501 repE (HsPar x) = repLE x
502 repE (SectionL x y) = do { a <- repLE x; b <- repLE y; repSectionL a b }
503 repE (SectionR x y) = do { a <- repLE x; b <- repLE y; repSectionR a b }
504 repE (HsCase e (MatchGroup ms _)) = do { arg <- repLE e
505 ; ms2 <- mapM repMatchTup ms
506 ; repCaseE arg (nonEmptyCoreList ms2) }
507 repE (HsIf x y z) = do
512 repE (HsLet bs e) = do { (ss,ds) <- repBinds bs
513 ; e2 <- addBinds ss (repLE e)
516 -- FIXME: I haven't got the types here right yet
517 repE (HsDo DoExpr sts body ty)
518 = do { (ss,zs) <- repLSts sts;
519 body' <- addBinds ss $ repLE body;
520 ret <- repNoBindSt body';
521 e <- repDoE (nonEmptyCoreList (zs ++ [ret]));
523 repE (HsDo ListComp sts body ty)
524 = do { (ss,zs) <- repLSts sts;
525 body' <- addBinds ss $ repLE body;
526 ret <- repNoBindSt body';
527 e <- repComp (nonEmptyCoreList (zs ++ [ret]));
529 repE e@(HsDo _ _ _ _) = notHandled "mdo and [: :]" (ppr e)
530 repE (ExplicitList ty es) = do { xs <- repLEs es; repListExp xs }
531 repE e@(ExplicitPArr ty es) = notHandled "Parallel arrays" (ppr e)
532 repE e@(ExplicitTuple es boxed)
533 | isBoxed boxed = do { xs <- repLEs es; repTup xs }
534 | otherwise = notHandled "Unboxed tuples" (ppr e)
535 repE (RecordCon c _ flds)
536 = do { x <- lookupLOcc c;
537 fs <- repFields flds;
539 repE (RecordUpd e flds _ _ _)
541 fs <- repFields flds;
544 repE (ExprWithTySig e ty) = do { e1 <- repLE e; t1 <- repLTy ty; repSigExp e1 t1 }
545 repE (ArithSeq _ aseq) =
547 From e -> do { ds1 <- repLE e; repFrom ds1 }
556 FromThenTo e1 e2 e3 -> do
560 repFromThenTo ds1 ds2 ds3
561 repE (HsSpliceE (HsSplice n _))
562 = do { mb_val <- dsLookupMetaEnv n
564 Just (Splice e) -> do { e' <- dsExpr e
566 other -> pprPanic "HsSplice" (ppr n) }
567 -- Should not happen; statically checked
569 repE e@(PArrSeq {}) = notHandled "Parallel arrays" (ppr e)
570 repE e@(HsCoreAnn {}) = notHandled "Core annotations" (ppr e)
571 repE e@(HsSCC {}) = notHandled "Cost centres" (ppr e)
572 repE e@(HsTickPragma {}) = notHandled "Tick Pragma" (ppr e)
573 repE e@(HsBracketOut {}) = notHandled "TH brackets" (ppr e)
574 repE e = notHandled "Expression form" (ppr e)
576 -----------------------------------------------------------------------------
577 -- Building representations of auxillary structures like Match, Clause, Stmt,
579 repMatchTup :: LMatch Name -> DsM (Core TH.MatchQ)
580 repMatchTup (L _ (Match [p] ty (GRHSs guards wheres))) =
581 do { ss1 <- mkGenSyms (collectPatBinders p)
582 ; addBinds ss1 $ do {
584 ; (ss2,ds) <- repBinds wheres
585 ; addBinds ss2 $ do {
586 ; gs <- repGuards guards
587 ; match <- repMatch p1 gs ds
588 ; wrapGenSyns (ss1++ss2) match }}}
589 repMatchTup other = panic "repMatchTup: case alt with more than one arg"
591 repClauseTup :: LMatch Name -> DsM (Core TH.ClauseQ)
592 repClauseTup (L _ (Match ps ty (GRHSs guards wheres))) =
593 do { ss1 <- mkGenSyms (collectPatsBinders ps)
594 ; addBinds ss1 $ do {
596 ; (ss2,ds) <- repBinds wheres
597 ; addBinds ss2 $ do {
598 gs <- repGuards guards
599 ; clause <- repClause ps1 gs ds
600 ; wrapGenSyns (ss1++ss2) clause }}}
602 repGuards :: [LGRHS Name] -> DsM (Core TH.BodyQ)
603 repGuards [L _ (GRHS [] e)]
604 = do {a <- repLE e; repNormal a }
606 = do { zs <- mapM process other;
607 let {(xs, ys) = unzip zs};
608 gd <- repGuarded (nonEmptyCoreList ys);
609 wrapGenSyns (concat xs) gd }
611 process :: LGRHS Name -> DsM ([GenSymBind], (Core (TH.Q (TH.Guard, TH.Exp))))
612 process (L _ (GRHS [L _ (ExprStmt e1 _ _)] e2))
613 = do { x <- repLNormalGE e1 e2;
615 process (L _ (GRHS ss rhs))
616 = do (gs, ss') <- repLSts ss
617 rhs' <- addBinds gs $ repLE rhs
618 g <- repPatGE (nonEmptyCoreList ss') rhs'
621 repFields :: HsRecordBinds Name -> DsM (Core [TH.Q TH.FieldExp])
622 repFields (HsRecFields { rec_flds = flds })
623 = do { fnames <- mapM lookupLOcc (map hsRecFieldId flds)
624 ; es <- mapM repLE (map hsRecFieldArg flds)
625 ; fs <- zipWithM repFieldExp fnames es
626 ; coreList fieldExpQTyConName fs }
629 -----------------------------------------------------------------------------
630 -- Representing Stmt's is tricky, especially if bound variables
631 -- shadow each other. Consider: [| do { x <- f 1; x <- f x; g x } |]
632 -- First gensym new names for every variable in any of the patterns.
633 -- both static (x'1 and x'2), and dynamic ((gensym "x") and (gensym "y"))
634 -- if variables didn't shaddow, the static gensym wouldn't be necessary
635 -- and we could reuse the original names (x and x).
637 -- do { x'1 <- gensym "x"
638 -- ; x'2 <- gensym "x"
639 -- ; doE [ BindSt (pvar x'1) [| f 1 |]
640 -- , BindSt (pvar x'2) [| f x |]
641 -- , NoBindSt [| g x |]
645 -- The strategy is to translate a whole list of do-bindings by building a
646 -- bigger environment, and a bigger set of meta bindings
647 -- (like: x'1 <- gensym "x" ) and then combining these with the translations
648 -- of the expressions within the Do
650 -----------------------------------------------------------------------------
651 -- The helper function repSts computes the translation of each sub expression
652 -- and a bunch of prefix bindings denoting the dynamic renaming.
654 repLSts :: [LStmt Name] -> DsM ([GenSymBind], [Core TH.StmtQ])
655 repLSts stmts = repSts (map unLoc stmts)
657 repSts :: [Stmt Name] -> DsM ([GenSymBind], [Core TH.StmtQ])
658 repSts (BindStmt p e _ _ : ss) =
660 ; ss1 <- mkGenSyms (collectPatBinders p)
661 ; addBinds ss1 $ do {
663 ; (ss2,zs) <- repSts ss
664 ; z <- repBindSt p1 e2
665 ; return (ss1++ss2, z : zs) }}
666 repSts (LetStmt bs : ss) =
667 do { (ss1,ds) <- repBinds bs
669 ; (ss2,zs) <- addBinds ss1 (repSts ss)
670 ; return (ss1++ss2, z : zs) }
671 repSts (ExprStmt e _ _ : ss) =
673 ; z <- repNoBindSt e2
674 ; (ss2,zs) <- repSts ss
675 ; return (ss2, z : zs) }
676 repSts [] = return ([],[])
677 repSts other = notHandled "Exotic statement" (ppr other)
680 -----------------------------------------------------------
682 -----------------------------------------------------------
684 repBinds :: HsLocalBinds Name -> DsM ([GenSymBind], Core [TH.DecQ])
685 repBinds EmptyLocalBinds
686 = do { core_list <- coreList decQTyConName []
687 ; return ([], core_list) }
689 repBinds b@(HsIPBinds _) = notHandled "Implicit parameters" (ppr b)
691 repBinds (HsValBinds decs)
692 = do { let { bndrs = map unLoc (collectHsValBinders decs) }
693 -- No need to worrry about detailed scopes within
694 -- the binding group, because we are talking Names
695 -- here, so we can safely treat it as a mutually
697 ; ss <- mkGenSyms bndrs
698 ; prs <- addBinds ss (rep_val_binds decs)
699 ; core_list <- coreList decQTyConName
700 (de_loc (sort_by_loc prs))
701 ; return (ss, core_list) }
703 rep_val_binds :: HsValBinds Name -> DsM [(SrcSpan, Core TH.DecQ)]
704 -- Assumes: all the binders of the binding are alrady in the meta-env
705 rep_val_binds (ValBindsOut binds sigs)
706 = do { core1 <- rep_binds' (unionManyBags (map snd binds))
707 ; core2 <- rep_sigs' sigs
708 ; return (core1 ++ core2) }
709 rep_val_binds (ValBindsIn binds sigs)
710 = panic "rep_val_binds: ValBindsIn"
712 rep_binds :: LHsBinds Name -> DsM [Core TH.DecQ]
713 rep_binds binds = do { binds_w_locs <- rep_binds' binds
714 ; return (de_loc (sort_by_loc binds_w_locs)) }
716 rep_binds' :: LHsBinds Name -> DsM [(SrcSpan, Core TH.DecQ)]
717 rep_binds' binds = mapM rep_bind (bagToList binds)
719 rep_bind :: LHsBind Name -> DsM (SrcSpan, Core TH.DecQ)
720 -- Assumes: all the binders of the binding are alrady in the meta-env
722 -- Note GHC treats declarations of a variable (not a pattern)
723 -- e.g. x = g 5 as a Fun MonoBinds. This is indicated by a single match
724 -- with an empty list of patterns
725 rep_bind (L loc (FunBind { fun_id = fn,
726 fun_matches = MatchGroup [L _ (Match [] ty (GRHSs guards wheres))] _ }))
727 = do { (ss,wherecore) <- repBinds wheres
728 ; guardcore <- addBinds ss (repGuards guards)
729 ; fn' <- lookupLBinder fn
731 ; ans <- repVal p guardcore wherecore
732 ; ans' <- wrapGenSyns ss ans
733 ; return (loc, ans') }
735 rep_bind (L loc (FunBind { fun_id = fn, fun_matches = MatchGroup ms _ }))
736 = do { ms1 <- mapM repClauseTup ms
737 ; fn' <- lookupLBinder fn
738 ; ans <- repFun fn' (nonEmptyCoreList ms1)
739 ; return (loc, ans) }
741 rep_bind (L loc (PatBind { pat_lhs = pat, pat_rhs = GRHSs guards wheres }))
742 = do { patcore <- repLP pat
743 ; (ss,wherecore) <- repBinds wheres
744 ; guardcore <- addBinds ss (repGuards guards)
745 ; ans <- repVal patcore guardcore wherecore
746 ; ans' <- wrapGenSyns ss ans
747 ; return (loc, ans') }
749 rep_bind (L loc (VarBind { var_id = v, var_rhs = e}))
750 = do { v' <- lookupBinder v
753 ; patcore <- repPvar v'
754 ; empty_decls <- coreList decQTyConName []
755 ; ans <- repVal patcore x empty_decls
756 ; return (srcLocSpan (getSrcLoc v), ans) }
758 rep_bind other = panic "rep_bind: AbsBinds"
760 -----------------------------------------------------------------------------
761 -- Since everything in a Bind is mutually recursive we need rename all
762 -- all the variables simultaneously. For example:
763 -- [| AndMonoBinds (f x = x + g 2) (g x = f 1 + 2) |] would translate to
764 -- do { f'1 <- gensym "f"
765 -- ; g'2 <- gensym "g"
766 -- ; [ do { x'3 <- gensym "x"; fun f'1 [pvar x'3] [| x + g2 |]},
767 -- do { x'4 <- gensym "x"; fun g'2 [pvar x'4] [| f 1 + 2 |]}
769 -- This requires collecting the bindings (f'1 <- gensym "f"), and the
770 -- environment ( f |-> f'1 ) from each binding, and then unioning them
771 -- together. As we do this we collect GenSymBinds's which represent the renamed
772 -- variables bound by the Bindings. In order not to lose track of these
773 -- representations we build a shadow datatype MB with the same structure as
774 -- MonoBinds, but which has slots for the representations
777 -----------------------------------------------------------------------------
778 -- GHC allows a more general form of lambda abstraction than specified
779 -- by Haskell 98. In particular it allows guarded lambda's like :
780 -- (\ x | even x -> 0 | odd x -> 1) at the moment we can't represent this in
781 -- Haskell Template's Meta.Exp type so we punt if it isn't a simple thing like
782 -- (\ p1 .. pn -> exp) by causing an error.
784 repLambda :: LMatch Name -> DsM (Core TH.ExpQ)
785 repLambda (L _ (Match ps _ (GRHSs [L _ (GRHS [] e)] EmptyLocalBinds)))
786 = do { let bndrs = collectPatsBinders ps ;
787 ; ss <- mkGenSyms bndrs
788 ; lam <- addBinds ss (
789 do { xs <- repLPs ps; body <- repLE e; repLam xs body })
790 ; wrapGenSyns ss lam }
792 repLambda (L _ m) = notHandled "Guarded labmdas" (pprMatch (LambdaExpr :: HsMatchContext Name) m)
795 -----------------------------------------------------------------------------
797 -- repP deals with patterns. It assumes that we have already
798 -- walked over the pattern(s) once to collect the binders, and
799 -- have extended the environment. So every pattern-bound
800 -- variable should already appear in the environment.
802 -- Process a list of patterns
803 repLPs :: [LPat Name] -> DsM (Core [TH.PatQ])
804 repLPs ps = do { ps' <- mapM repLP ps ;
805 coreList patQTyConName ps' }
807 repLP :: LPat Name -> DsM (Core TH.PatQ)
808 repLP (L _ p) = repP p
810 repP :: Pat Name -> DsM (Core TH.PatQ)
811 repP (WildPat _) = repPwild
812 repP (LitPat l) = do { l2 <- repLiteral l; repPlit l2 }
813 repP (VarPat x) = do { x' <- lookupBinder x; repPvar x' }
814 repP (LazyPat p) = do { p1 <- repLP p; repPtilde p1 }
815 repP (AsPat x p) = do { x' <- lookupLBinder x; p1 <- repLP p; repPaspat x' p1 }
816 repP (ParPat p) = repLP p
817 repP (ListPat ps _) = do { qs <- repLPs ps; repPlist qs }
818 repP (TuplePat ps _ _) = do { qs <- repLPs ps; repPtup qs }
819 repP (ConPatIn dc details)
820 = do { con_str <- lookupLOcc dc
822 PrefixCon ps -> do { qs <- repLPs ps; repPcon con_str qs }
823 RecCon rec -> do { let flds = rec_flds rec
824 ; vs <- sequence $ map lookupLOcc (map hsRecFieldId flds)
825 ; ps <- sequence $ map repLP (map hsRecFieldArg flds)
826 ; fps <- zipWithM (\x y -> rep2 fieldPatName [unC x,unC y]) vs ps
827 ; fps' <- coreList fieldPatQTyConName fps
828 ; repPrec con_str fps' }
829 InfixCon p1 p2 -> do { p1' <- repLP p1;
831 repPinfix p1' con_str p2' }
833 repP (NPat l Nothing _) = do { a <- repOverloadedLiteral l; repPlit a }
834 repP p@(NPat l (Just _) _) = notHandled "Negative overloaded patterns" (ppr p)
835 repP p@(SigPatIn {}) = notHandled "Type signatures in patterns" (ppr p)
836 -- The problem is to do with scoped type variables.
837 -- To implement them, we have to implement the scoping rules
838 -- here in DsMeta, and I don't want to do that today!
839 -- do { p' <- repLP p; t' <- repLTy t; repPsig p' t' }
840 -- repPsig :: Core TH.PatQ -> Core TH.TypeQ -> DsM (Core TH.PatQ)
841 -- repPsig (MkC p) (MkC t) = rep2 sigPName [p, t]
843 repP other = notHandled "Exotic pattern" (ppr other)
845 ----------------------------------------------------------
846 -- Declaration ordering helpers
848 sort_by_loc :: [(SrcSpan, a)] -> [(SrcSpan, a)]
849 sort_by_loc xs = sortBy comp xs
850 where comp x y = compare (fst x) (fst y)
852 de_loc :: [(a, b)] -> [b]
855 ----------------------------------------------------------
856 -- The meta-environment
858 -- A name/identifier association for fresh names of locally bound entities
859 type GenSymBind = (Name, Id) -- Gensym the string and bind it to the Id
860 -- I.e. (x, x_id) means
861 -- let x_id = gensym "x" in ...
863 -- Generate a fresh name for a locally bound entity
865 mkGenSyms :: [Name] -> DsM [GenSymBind]
866 -- We can use the existing name. For example:
867 -- [| \x_77 -> x_77 + x_77 |]
869 -- do { x_77 <- genSym "x"; .... }
870 -- We use the same x_77 in the desugared program, but with the type Bndr
873 -- We do make it an Internal name, though (hence localiseName)
875 -- Nevertheless, it's monadic because we have to generate nameTy
876 mkGenSyms ns = do { var_ty <- lookupType nameTyConName
877 ; return [(nm, mkLocalId (localiseName nm) var_ty) | nm <- ns] }
880 addBinds :: [GenSymBind] -> DsM a -> DsM a
881 -- Add a list of fresh names for locally bound entities to the
882 -- meta environment (which is part of the state carried around
883 -- by the desugarer monad)
884 addBinds bs m = dsExtendMetaEnv (mkNameEnv [(n,Bound id) | (n,id) <- bs]) m
886 -- Look up a locally bound name
888 lookupLBinder :: Located Name -> DsM (Core TH.Name)
889 lookupLBinder (L _ n) = lookupBinder n
891 lookupBinder :: Name -> DsM (Core TH.Name)
893 = do { mb_val <- dsLookupMetaEnv n;
895 Just (Bound x) -> return (coreVar x)
896 other -> failWithDs msg }
898 msg = ptext (sLit "DsMeta: failed binder lookup when desugaring a TH bracket:") <+> ppr n
900 -- Look up a name that is either locally bound or a global name
902 -- * If it is a global name, generate the "original name" representation (ie,
903 -- the <module>:<name> form) for the associated entity
905 lookupLOcc :: Located Name -> DsM (Core TH.Name)
906 -- Lookup an occurrence; it can't be a splice.
907 -- Use the in-scope bindings if they exist
908 lookupLOcc (L _ n) = lookupOcc n
910 lookupOcc :: Name -> DsM (Core TH.Name)
912 = do { mb_val <- dsLookupMetaEnv n ;
914 Nothing -> globalVar n
915 Just (Bound x) -> return (coreVar x)
916 Just (Splice _) -> pprPanic "repE:lookupOcc" (ppr n)
919 lookupTvOcc :: Name -> DsM (Core TH.Name)
920 -- Type variables can't be staged and are not lexically scoped in TH
922 = do { mb_val <- dsLookupMetaEnv n ;
924 Just (Bound x) -> return (coreVar x)
925 other -> failWithDs msg
928 msg = vcat [ ptext (sLit "Illegal lexically-scoped type variable") <+> quotes (ppr n)
929 , ptext (sLit "Lexically scoped type variables are not supported by Template Haskell") ]
931 globalVar :: Name -> DsM (Core TH.Name)
932 -- Not bound by the meta-env
933 -- Could be top-level; or could be local
934 -- f x = $(g [| x |])
935 -- Here the x will be local
937 | isExternalName name
938 = do { MkC mod <- coreStringLit name_mod
939 ; MkC pkg <- coreStringLit name_pkg
940 ; MkC occ <- occNameLit name
941 ; rep2 mk_varg [pkg,mod,occ] }
943 = do { MkC occ <- occNameLit name
944 ; MkC uni <- coreIntLit (getKey (getUnique name))
945 ; rep2 mkNameLName [occ,uni] }
947 mod = nameModule name
948 name_mod = moduleNameString (moduleName mod)
949 name_pkg = packageIdString (modulePackageId mod)
950 name_occ = nameOccName name
951 mk_varg | OccName.isDataOcc name_occ = mkNameG_dName
952 | OccName.isVarOcc name_occ = mkNameG_vName
953 | OccName.isTcOcc name_occ = mkNameG_tcName
954 | otherwise = pprPanic "DsMeta.globalVar" (ppr name)
956 lookupType :: Name -- Name of type constructor (e.g. TH.ExpQ)
957 -> DsM Type -- The type
958 lookupType tc_name = do { tc <- dsLookupTyCon tc_name ;
959 return (mkTyConApp tc []) }
961 wrapGenSyns :: [GenSymBind]
962 -> Core (TH.Q a) -> DsM (Core (TH.Q a))
963 -- wrapGenSyns [(nm1,id1), (nm2,id2)] y
964 -- --> bindQ (gensym nm1) (\ id1 ->
965 -- bindQ (gensym nm2 (\ id2 ->
968 wrapGenSyns binds body@(MkC b)
969 = do { var_ty <- lookupType nameTyConName
972 [elt_ty] = tcTyConAppArgs (exprType b)
973 -- b :: Q a, so we can get the type 'a' by looking at the
974 -- argument type. NB: this relies on Q being a data/newtype,
975 -- not a type synonym
977 go var_ty [] = return body
978 go var_ty ((name,id) : binds)
979 = do { MkC body' <- go var_ty binds
980 ; lit_str <- occNameLit name
981 ; gensym_app <- repGensym lit_str
982 ; repBindQ var_ty elt_ty
983 gensym_app (MkC (Lam id body')) }
985 -- Just like wrapGenSym, but don't actually do the gensym
986 -- Instead use the existing name:
987 -- let x = "x" in ...
988 -- Only used for [Decl], and for the class ops in class
989 -- and instance decls
990 wrapNongenSyms :: [GenSymBind] -> Core a -> DsM (Core a)
991 wrapNongenSyms binds (MkC body)
992 = do { binds' <- mapM do_one binds ;
993 return (MkC (mkLets binds' body)) }
996 = do { MkC lit_str <- occNameLit name
997 ; MkC var <- rep2 mkNameName [lit_str]
998 ; return (NonRec id var) }
1000 occNameLit :: Name -> DsM (Core String)
1001 occNameLit n = coreStringLit (occNameString (nameOccName n))
1004 -- %*********************************************************************
1006 -- Constructing code
1008 -- %*********************************************************************
1010 -----------------------------------------------------------------------------
1011 -- PHANTOM TYPES for consistency. In order to make sure we do this correct
1012 -- we invent a new datatype which uses phantom types.
1014 newtype Core a = MkC CoreExpr
1017 rep2 :: Name -> [ CoreExpr ] -> DsM (Core a)
1018 rep2 n xs = do { id <- dsLookupGlobalId n
1019 ; return (MkC (foldl App (Var id) xs)) }
1021 -- Then we make "repConstructors" which use the phantom types for each of the
1022 -- smart constructors of the Meta.Meta datatypes.
1025 -- %*********************************************************************
1027 -- The 'smart constructors'
1029 -- %*********************************************************************
1031 --------------- Patterns -----------------
1032 repPlit :: Core TH.Lit -> DsM (Core TH.PatQ)
1033 repPlit (MkC l) = rep2 litPName [l]
1035 repPvar :: Core TH.Name -> DsM (Core TH.PatQ)
1036 repPvar (MkC s) = rep2 varPName [s]
1038 repPtup :: Core [TH.PatQ] -> DsM (Core TH.PatQ)
1039 repPtup (MkC ps) = rep2 tupPName [ps]
1041 repPcon :: Core TH.Name -> Core [TH.PatQ] -> DsM (Core TH.PatQ)
1042 repPcon (MkC s) (MkC ps) = rep2 conPName [s, ps]
1044 repPrec :: Core TH.Name -> Core [(TH.Name,TH.PatQ)] -> DsM (Core TH.PatQ)
1045 repPrec (MkC c) (MkC rps) = rep2 recPName [c,rps]
1047 repPinfix :: Core TH.PatQ -> Core TH.Name -> Core TH.PatQ -> DsM (Core TH.PatQ)
1048 repPinfix (MkC p1) (MkC n) (MkC p2) = rep2 infixPName [p1, n, p2]
1050 repPtilde :: Core TH.PatQ -> DsM (Core TH.PatQ)
1051 repPtilde (MkC p) = rep2 tildePName [p]
1053 repPaspat :: Core TH.Name -> Core TH.PatQ -> DsM (Core TH.PatQ)
1054 repPaspat (MkC s) (MkC p) = rep2 asPName [s, p]
1056 repPwild :: DsM (Core TH.PatQ)
1057 repPwild = rep2 wildPName []
1059 repPlist :: Core [TH.PatQ] -> DsM (Core TH.PatQ)
1060 repPlist (MkC ps) = rep2 listPName [ps]
1062 --------------- Expressions -----------------
1063 repVarOrCon :: Name -> Core TH.Name -> DsM (Core TH.ExpQ)
1064 repVarOrCon vc str | isDataOcc (nameOccName vc) = repCon str
1065 | otherwise = repVar str
1067 repVar :: Core TH.Name -> DsM (Core TH.ExpQ)
1068 repVar (MkC s) = rep2 varEName [s]
1070 repCon :: Core TH.Name -> DsM (Core TH.ExpQ)
1071 repCon (MkC s) = rep2 conEName [s]
1073 repLit :: Core TH.Lit -> DsM (Core TH.ExpQ)
1074 repLit (MkC c) = rep2 litEName [c]
1076 repApp :: Core TH.ExpQ -> Core TH.ExpQ -> DsM (Core TH.ExpQ)
1077 repApp (MkC x) (MkC y) = rep2 appEName [x,y]
1079 repLam :: Core [TH.PatQ] -> Core TH.ExpQ -> DsM (Core TH.ExpQ)
1080 repLam (MkC ps) (MkC e) = rep2 lamEName [ps, e]
1082 repTup :: Core [TH.ExpQ] -> DsM (Core TH.ExpQ)
1083 repTup (MkC es) = rep2 tupEName [es]
1085 repCond :: Core TH.ExpQ -> Core TH.ExpQ -> Core TH.ExpQ -> DsM (Core TH.ExpQ)
1086 repCond (MkC x) (MkC y) (MkC z) = rep2 condEName [x,y,z]
1088 repLetE :: Core [TH.DecQ] -> Core TH.ExpQ -> DsM (Core TH.ExpQ)
1089 repLetE (MkC ds) (MkC e) = rep2 letEName [ds, e]
1091 repCaseE :: Core TH.ExpQ -> Core [TH.MatchQ] -> DsM( Core TH.ExpQ)
1092 repCaseE (MkC e) (MkC ms) = rep2 caseEName [e, ms]
1094 repDoE :: Core [TH.StmtQ] -> DsM (Core TH.ExpQ)
1095 repDoE (MkC ss) = rep2 doEName [ss]
1097 repComp :: Core [TH.StmtQ] -> DsM (Core TH.ExpQ)
1098 repComp (MkC ss) = rep2 compEName [ss]
1100 repListExp :: Core [TH.ExpQ] -> DsM (Core TH.ExpQ)
1101 repListExp (MkC es) = rep2 listEName [es]
1103 repSigExp :: Core TH.ExpQ -> Core TH.TypeQ -> DsM (Core TH.ExpQ)
1104 repSigExp (MkC e) (MkC t) = rep2 sigEName [e,t]
1106 repRecCon :: Core TH.Name -> Core [TH.Q TH.FieldExp]-> DsM (Core TH.ExpQ)
1107 repRecCon (MkC c) (MkC fs) = rep2 recConEName [c,fs]
1109 repRecUpd :: Core TH.ExpQ -> Core [TH.Q TH.FieldExp] -> DsM (Core TH.ExpQ)
1110 repRecUpd (MkC e) (MkC fs) = rep2 recUpdEName [e,fs]
1112 repFieldExp :: Core TH.Name -> Core TH.ExpQ -> DsM (Core (TH.Q TH.FieldExp))
1113 repFieldExp (MkC n) (MkC x) = rep2 fieldExpName [n,x]
1115 repInfixApp :: Core TH.ExpQ -> Core TH.ExpQ -> Core TH.ExpQ -> DsM (Core TH.ExpQ)
1116 repInfixApp (MkC x) (MkC y) (MkC z) = rep2 infixAppName [x,y,z]
1118 repSectionL :: Core TH.ExpQ -> Core TH.ExpQ -> DsM (Core TH.ExpQ)
1119 repSectionL (MkC x) (MkC y) = rep2 sectionLName [x,y]
1121 repSectionR :: Core TH.ExpQ -> Core TH.ExpQ -> DsM (Core TH.ExpQ)
1122 repSectionR (MkC x) (MkC y) = rep2 sectionRName [x,y]
1124 ------------ Right hand sides (guarded expressions) ----
1125 repGuarded :: Core [TH.Q (TH.Guard, TH.Exp)] -> DsM (Core TH.BodyQ)
1126 repGuarded (MkC pairs) = rep2 guardedBName [pairs]
1128 repNormal :: Core TH.ExpQ -> DsM (Core TH.BodyQ)
1129 repNormal (MkC e) = rep2 normalBName [e]
1131 ------------ Guards ----
1132 repLNormalGE :: LHsExpr Name -> LHsExpr Name -> DsM (Core (TH.Q (TH.Guard, TH.Exp)))
1133 repLNormalGE g e = do g' <- repLE g
1137 repNormalGE :: Core TH.ExpQ -> Core TH.ExpQ -> DsM (Core (TH.Q (TH.Guard, TH.Exp)))
1138 repNormalGE (MkC g) (MkC e) = rep2 normalGEName [g, e]
1140 repPatGE :: Core [TH.StmtQ] -> Core TH.ExpQ -> DsM (Core (TH.Q (TH.Guard, TH.Exp)))
1141 repPatGE (MkC ss) (MkC e) = rep2 patGEName [ss, e]
1143 ------------- Stmts -------------------
1144 repBindSt :: Core TH.PatQ -> Core TH.ExpQ -> DsM (Core TH.StmtQ)
1145 repBindSt (MkC p) (MkC e) = rep2 bindSName [p,e]
1147 repLetSt :: Core [TH.DecQ] -> DsM (Core TH.StmtQ)
1148 repLetSt (MkC ds) = rep2 letSName [ds]
1150 repNoBindSt :: Core TH.ExpQ -> DsM (Core TH.StmtQ)
1151 repNoBindSt (MkC e) = rep2 noBindSName [e]
1153 -------------- Range (Arithmetic sequences) -----------
1154 repFrom :: Core TH.ExpQ -> DsM (Core TH.ExpQ)
1155 repFrom (MkC x) = rep2 fromEName [x]
1157 repFromThen :: Core TH.ExpQ -> Core TH.ExpQ -> DsM (Core TH.ExpQ)
1158 repFromThen (MkC x) (MkC y) = rep2 fromThenEName [x,y]
1160 repFromTo :: Core TH.ExpQ -> Core TH.ExpQ -> DsM (Core TH.ExpQ)
1161 repFromTo (MkC x) (MkC y) = rep2 fromToEName [x,y]
1163 repFromThenTo :: Core TH.ExpQ -> Core TH.ExpQ -> Core TH.ExpQ -> DsM (Core TH.ExpQ)
1164 repFromThenTo (MkC x) (MkC y) (MkC z) = rep2 fromThenToEName [x,y,z]
1166 ------------ Match and Clause Tuples -----------
1167 repMatch :: Core TH.PatQ -> Core TH.BodyQ -> Core [TH.DecQ] -> DsM (Core TH.MatchQ)
1168 repMatch (MkC p) (MkC bod) (MkC ds) = rep2 matchName [p, bod, ds]
1170 repClause :: Core [TH.PatQ] -> Core TH.BodyQ -> Core [TH.DecQ] -> DsM (Core TH.ClauseQ)
1171 repClause (MkC ps) (MkC bod) (MkC ds) = rep2 clauseName [ps, bod, ds]
1173 -------------- Dec -----------------------------
1174 repVal :: Core TH.PatQ -> Core TH.BodyQ -> Core [TH.DecQ] -> DsM (Core TH.DecQ)
1175 repVal (MkC p) (MkC b) (MkC ds) = rep2 valDName [p, b, ds]
1177 repFun :: Core TH.Name -> Core [TH.ClauseQ] -> DsM (Core TH.DecQ)
1178 repFun (MkC nm) (MkC b) = rep2 funDName [nm, b]
1180 repData :: Core TH.CxtQ -> Core TH.Name -> Core [TH.Name] -> Core [TH.ConQ] -> Core [TH.Name] -> DsM (Core TH.DecQ)
1181 repData (MkC cxt) (MkC nm) (MkC tvs) (MkC cons) (MkC derivs)
1182 = rep2 dataDName [cxt, nm, tvs, cons, derivs]
1184 repNewtype :: Core TH.CxtQ -> Core TH.Name -> Core [TH.Name] -> Core TH.ConQ -> Core [TH.Name] -> DsM (Core TH.DecQ)
1185 repNewtype (MkC cxt) (MkC nm) (MkC tvs) (MkC con) (MkC derivs)
1186 = rep2 newtypeDName [cxt, nm, tvs, con, derivs]
1188 repTySyn :: Core TH.Name -> Core [TH.Name] -> Core TH.TypeQ -> DsM (Core TH.DecQ)
1189 repTySyn (MkC nm) (MkC tvs) (MkC rhs) = rep2 tySynDName [nm, tvs, rhs]
1191 repInst :: Core TH.CxtQ -> Core TH.TypeQ -> Core [TH.DecQ] -> DsM (Core TH.DecQ)
1192 repInst (MkC cxt) (MkC ty) (MkC ds) = rep2 instanceDName [cxt, ty, ds]
1194 repClass :: Core TH.CxtQ -> Core TH.Name -> Core [TH.Name] -> Core [TH.FunDep] -> Core [TH.DecQ] -> DsM (Core TH.DecQ)
1195 repClass (MkC cxt) (MkC cls) (MkC tvs) (MkC fds) (MkC ds) = rep2 classDName [cxt, cls, tvs, fds, ds]
1197 repFunDep :: Core [TH.Name] -> Core [TH.Name] -> DsM (Core TH.FunDep)
1198 repFunDep (MkC xs) (MkC ys) = rep2 funDepName [xs, ys]
1200 repProto :: Core TH.Name -> Core TH.TypeQ -> DsM (Core TH.DecQ)
1201 repProto (MkC s) (MkC ty) = rep2 sigDName [s, ty]
1203 repCtxt :: Core [TH.TypeQ] -> DsM (Core TH.CxtQ)
1204 repCtxt (MkC tys) = rep2 cxtName [tys]
1206 repConstr :: Core TH.Name -> HsConDeclDetails Name
1207 -> DsM (Core TH.ConQ)
1208 repConstr con (PrefixCon ps)
1209 = do arg_tys <- mapM repBangTy ps
1210 arg_tys1 <- coreList strictTypeQTyConName arg_tys
1211 rep2 normalCName [unC con, unC arg_tys1]
1212 repConstr con (RecCon ips)
1213 = do arg_vs <- mapM lookupLOcc (map cd_fld_name ips)
1214 arg_tys <- mapM repBangTy (map cd_fld_type ips)
1215 arg_vtys <- zipWithM (\x y -> rep2 varStrictTypeName [unC x, unC y])
1217 arg_vtys' <- coreList varStrictTypeQTyConName arg_vtys
1218 rep2 recCName [unC con, unC arg_vtys']
1219 repConstr con (InfixCon st1 st2)
1220 = do arg1 <- repBangTy st1
1221 arg2 <- repBangTy st2
1222 rep2 infixCName [unC arg1, unC con, unC arg2]
1224 ------------ Types -------------------
1226 repTForall :: Core [TH.Name] -> Core TH.CxtQ -> Core TH.TypeQ -> DsM (Core TH.TypeQ)
1227 repTForall (MkC tvars) (MkC ctxt) (MkC ty)
1228 = rep2 forallTName [tvars, ctxt, ty]
1230 repTvar :: Core TH.Name -> DsM (Core TH.TypeQ)
1231 repTvar (MkC s) = rep2 varTName [s]
1233 repTapp :: Core TH.TypeQ -> Core TH.TypeQ -> DsM (Core TH.TypeQ)
1234 repTapp (MkC t1) (MkC t2) = rep2 appTName [t1,t2]
1236 repTapps :: Core TH.TypeQ -> [Core TH.TypeQ] -> DsM (Core TH.TypeQ)
1237 repTapps f [] = return f
1238 repTapps f (t:ts) = do { f1 <- repTapp f t; repTapps f1 ts }
1240 --------- Type constructors --------------
1242 repNamedTyCon :: Core TH.Name -> DsM (Core TH.TypeQ)
1243 repNamedTyCon (MkC s) = rep2 conTName [s]
1245 repTupleTyCon :: Int -> DsM (Core TH.TypeQ)
1246 -- Note: not Core Int; it's easier to be direct here
1247 repTupleTyCon i = rep2 tupleTName [mkIntExpr (fromIntegral i)]
1249 repArrowTyCon :: DsM (Core TH.TypeQ)
1250 repArrowTyCon = rep2 arrowTName []
1252 repListTyCon :: DsM (Core TH.TypeQ)
1253 repListTyCon = rep2 listTName []
1256 ----------------------------------------------------------
1259 repLiteral :: HsLit -> DsM (Core TH.Lit)
1261 = do lit' <- case lit of
1262 HsIntPrim i -> mk_integer i
1263 HsWordPrim w -> mk_integer w
1264 HsInt i -> mk_integer i
1265 HsFloatPrim r -> mk_rational r
1266 HsDoublePrim r -> mk_rational r
1268 lit_expr <- dsLit lit'
1270 Just lit_name -> rep2 lit_name [lit_expr]
1271 Nothing -> notHandled "Exotic literal" (ppr lit)
1273 mb_lit_name = case lit of
1274 HsInteger _ _ -> Just integerLName
1275 HsInt _ -> Just integerLName
1276 HsIntPrim _ -> Just intPrimLName
1277 HsWordPrim _ -> Just wordPrimLName
1278 HsFloatPrim _ -> Just floatPrimLName
1279 HsDoublePrim _ -> Just doublePrimLName
1280 HsChar _ -> Just charLName
1281 HsString _ -> Just stringLName
1282 HsRat _ _ -> Just rationalLName
1285 mk_integer i = do integer_ty <- lookupType integerTyConName
1286 return $ HsInteger i integer_ty
1287 mk_rational r = do rat_ty <- lookupType rationalTyConName
1288 return $ HsRat r rat_ty
1289 mk_string s = do string_ty <- lookupType stringTyConName
1292 repOverloadedLiteral :: HsOverLit Name -> DsM (Core TH.Lit)
1293 repOverloadedLiteral (HsIntegral i _ _) = do { lit <- mk_integer i; repLiteral lit }
1294 repOverloadedLiteral (HsFractional f _ _) = do { lit <- mk_rational f; repLiteral lit }
1295 repOverloadedLiteral (HsIsString s _ _) = do { lit <- mk_string s; repLiteral lit }
1296 -- The type Rational will be in the environment, becuase
1297 -- the smart constructor 'TH.Syntax.rationalL' uses it in its type,
1298 -- and rationalL is sucked in when any TH stuff is used
1300 --------------- Miscellaneous -------------------
1302 repGensym :: Core String -> DsM (Core (TH.Q TH.Name))
1303 repGensym (MkC lit_str) = rep2 newNameName [lit_str]
1305 repBindQ :: Type -> Type -- a and b
1306 -> Core (TH.Q a) -> Core (a -> TH.Q b) -> DsM (Core (TH.Q b))
1307 repBindQ ty_a ty_b (MkC x) (MkC y)
1308 = rep2 bindQName [Type ty_a, Type ty_b, x, y]
1310 repSequenceQ :: Type -> Core [TH.Q a] -> DsM (Core (TH.Q [a]))
1311 repSequenceQ ty_a (MkC list)
1312 = rep2 sequenceQName [Type ty_a, list]
1314 ------------ Lists and Tuples -------------------
1315 -- turn a list of patterns into a single pattern matching a list
1317 coreList :: Name -- Of the TyCon of the element type
1318 -> [Core a] -> DsM (Core [a])
1320 = do { elt_ty <- lookupType tc_name; return (coreList' elt_ty es) }
1322 coreList' :: Type -- The element type
1323 -> [Core a] -> Core [a]
1324 coreList' elt_ty es = MkC (mkListExpr elt_ty (map unC es ))
1326 nonEmptyCoreList :: [Core a] -> Core [a]
1327 -- The list must be non-empty so we can get the element type
1328 -- Otherwise use coreList
1329 nonEmptyCoreList [] = panic "coreList: empty argument"
1330 nonEmptyCoreList xs@(MkC x:_) = MkC (mkListExpr (exprType x) (map unC xs))
1332 corePair :: (Core a, Core b) -> Core (a,b)
1333 corePair (MkC x, MkC y) = MkC (mkCoreTup [x,y])
1335 coreStringLit :: String -> DsM (Core String)
1336 coreStringLit s = do { z <- mkStringExpr s; return(MkC z) }
1338 coreIntLit :: Int -> DsM (Core Int)
1339 coreIntLit i = return (MkC (mkIntExpr (fromIntegral i)))
1341 coreVar :: Id -> Core TH.Name -- The Id has type Name
1342 coreVar id = MkC (Var id)
1344 ----------------- Failure -----------------------
1345 notHandled :: String -> SDoc -> DsM a
1346 notHandled what doc = failWithDs msg
1348 msg = hang (text what <+> ptext (sLit "not (yet) handled by Template Haskell"))
1352 -- %************************************************************************
1354 -- The known-key names for Template Haskell
1356 -- %************************************************************************
1358 -- To add a name, do three things
1360 -- 1) Allocate a key
1362 -- 3) Add the name to knownKeyNames
1364 templateHaskellNames :: [Name]
1365 -- The names that are implicitly mentioned by ``bracket''
1366 -- Should stay in sync with the import list of DsMeta
1368 templateHaskellNames = [
1369 returnQName, bindQName, sequenceQName, newNameName, liftName,
1370 mkNameName, mkNameG_vName, mkNameG_dName, mkNameG_tcName, mkNameLName,
1373 charLName, stringLName, integerLName, intPrimLName, wordPrimLName,
1374 floatPrimLName, doublePrimLName, rationalLName,
1376 litPName, varPName, tupPName, conPName, tildePName, infixPName,
1377 asPName, wildPName, recPName, listPName, sigPName,
1385 varEName, conEName, litEName, appEName, infixEName,
1386 infixAppName, sectionLName, sectionRName, lamEName, tupEName,
1387 condEName, letEName, caseEName, doEName, compEName,
1388 fromEName, fromThenEName, fromToEName, fromThenToEName,
1389 listEName, sigEName, recConEName, recUpdEName,
1393 guardedBName, normalBName,
1395 normalGEName, patGEName,
1397 bindSName, letSName, noBindSName, parSName,
1399 funDName, valDName, dataDName, newtypeDName, tySynDName,
1400 classDName, instanceDName, sigDName, forImpDName,
1404 isStrictName, notStrictName,
1406 normalCName, recCName, infixCName, forallCName,
1412 forallTName, varTName, conTName, appTName,
1413 tupleTName, arrowTName, listTName,
1415 cCallName, stdCallName,
1424 qTyConName, nameTyConName, patTyConName, fieldPatTyConName, matchQTyConName,
1425 clauseQTyConName, expQTyConName, fieldExpTyConName, stmtQTyConName,
1426 decQTyConName, conQTyConName, strictTypeQTyConName,
1427 varStrictTypeQTyConName, typeQTyConName, expTyConName, decTyConName,
1428 typeTyConName, matchTyConName, clauseTyConName, patQTyConName,
1429 fieldPatQTyConName, fieldExpQTyConName, funDepTyConName,
1432 quoteExpName, quotePatName]
1435 thSyn = mkTHModule (fsLit "Language.Haskell.TH.Syntax")
1436 thLib = mkTHModule (fsLit "Language.Haskell.TH.Lib")
1437 qqLib = mkTHModule (fsLit "Language.Haskell.TH.Quote")
1439 mkTHModule m = mkModule thPackageId (mkModuleNameFS m)
1441 libFun = mk_known_key_name OccName.varName thLib
1442 libTc = mk_known_key_name OccName.tcName thLib
1443 thFun = mk_known_key_name OccName.varName thSyn
1444 thTc = mk_known_key_name OccName.tcName thSyn
1445 qqFun = mk_known_key_name OccName.varName qqLib
1447 -------------------- TH.Syntax -----------------------
1448 qTyConName = thTc (fsLit "Q") qTyConKey
1449 nameTyConName = thTc (fsLit "Name") nameTyConKey
1450 fieldExpTyConName = thTc (fsLit "FieldExp") fieldExpTyConKey
1451 patTyConName = thTc (fsLit "Pat") patTyConKey
1452 fieldPatTyConName = thTc (fsLit "FieldPat") fieldPatTyConKey
1453 expTyConName = thTc (fsLit "Exp") expTyConKey
1454 decTyConName = thTc (fsLit "Dec") decTyConKey
1455 typeTyConName = thTc (fsLit "Type") typeTyConKey
1456 matchTyConName = thTc (fsLit "Match") matchTyConKey
1457 clauseTyConName = thTc (fsLit "Clause") clauseTyConKey
1458 funDepTyConName = thTc (fsLit "FunDep") funDepTyConKey
1460 returnQName = thFun (fsLit "returnQ") returnQIdKey
1461 bindQName = thFun (fsLit "bindQ") bindQIdKey
1462 sequenceQName = thFun (fsLit "sequenceQ") sequenceQIdKey
1463 newNameName = thFun (fsLit "newName") newNameIdKey
1464 liftName = thFun (fsLit "lift") liftIdKey
1465 mkNameName = thFun (fsLit "mkName") mkNameIdKey
1466 mkNameG_vName = thFun (fsLit "mkNameG_v") mkNameG_vIdKey
1467 mkNameG_dName = thFun (fsLit "mkNameG_d") mkNameG_dIdKey
1468 mkNameG_tcName = thFun (fsLit "mkNameG_tc") mkNameG_tcIdKey
1469 mkNameLName = thFun (fsLit "mkNameL") mkNameLIdKey
1472 -------------------- TH.Lib -----------------------
1474 charLName = libFun (fsLit "charL") charLIdKey
1475 stringLName = libFun (fsLit "stringL") stringLIdKey
1476 integerLName = libFun (fsLit "integerL") integerLIdKey
1477 intPrimLName = libFun (fsLit "intPrimL") intPrimLIdKey
1478 wordPrimLName = libFun (fsLit "wordPrimL") wordPrimLIdKey
1479 floatPrimLName = libFun (fsLit "floatPrimL") floatPrimLIdKey
1480 doublePrimLName = libFun (fsLit "doublePrimL") doublePrimLIdKey
1481 rationalLName = libFun (fsLit "rationalL") rationalLIdKey
1484 litPName = libFun (fsLit "litP") litPIdKey
1485 varPName = libFun (fsLit "varP") varPIdKey
1486 tupPName = libFun (fsLit "tupP") tupPIdKey
1487 conPName = libFun (fsLit "conP") conPIdKey
1488 infixPName = libFun (fsLit "infixP") infixPIdKey
1489 tildePName = libFun (fsLit "tildeP") tildePIdKey
1490 asPName = libFun (fsLit "asP") asPIdKey
1491 wildPName = libFun (fsLit "wildP") wildPIdKey
1492 recPName = libFun (fsLit "recP") recPIdKey
1493 listPName = libFun (fsLit "listP") listPIdKey
1494 sigPName = libFun (fsLit "sigP") sigPIdKey
1496 -- type FieldPat = ...
1497 fieldPatName = libFun (fsLit "fieldPat") fieldPatIdKey
1500 matchName = libFun (fsLit "match") matchIdKey
1502 -- data Clause = ...
1503 clauseName = libFun (fsLit "clause") clauseIdKey
1506 varEName = libFun (fsLit "varE") varEIdKey
1507 conEName = libFun (fsLit "conE") conEIdKey
1508 litEName = libFun (fsLit "litE") litEIdKey
1509 appEName = libFun (fsLit "appE") appEIdKey
1510 infixEName = libFun (fsLit "infixE") infixEIdKey
1511 infixAppName = libFun (fsLit "infixApp") infixAppIdKey
1512 sectionLName = libFun (fsLit "sectionL") sectionLIdKey
1513 sectionRName = libFun (fsLit "sectionR") sectionRIdKey
1514 lamEName = libFun (fsLit "lamE") lamEIdKey
1515 tupEName = libFun (fsLit "tupE") tupEIdKey
1516 condEName = libFun (fsLit "condE") condEIdKey
1517 letEName = libFun (fsLit "letE") letEIdKey
1518 caseEName = libFun (fsLit "caseE") caseEIdKey
1519 doEName = libFun (fsLit "doE") doEIdKey
1520 compEName = libFun (fsLit "compE") compEIdKey
1521 -- ArithSeq skips a level
1522 fromEName = libFun (fsLit "fromE") fromEIdKey
1523 fromThenEName = libFun (fsLit "fromThenE") fromThenEIdKey
1524 fromToEName = libFun (fsLit "fromToE") fromToEIdKey
1525 fromThenToEName = libFun (fsLit "fromThenToE") fromThenToEIdKey
1527 listEName = libFun (fsLit "listE") listEIdKey
1528 sigEName = libFun (fsLit "sigE") sigEIdKey
1529 recConEName = libFun (fsLit "recConE") recConEIdKey
1530 recUpdEName = libFun (fsLit "recUpdE") recUpdEIdKey
1532 -- type FieldExp = ...
1533 fieldExpName = libFun (fsLit "fieldExp") fieldExpIdKey
1536 guardedBName = libFun (fsLit "guardedB") guardedBIdKey
1537 normalBName = libFun (fsLit "normalB") normalBIdKey
1540 normalGEName = libFun (fsLit "normalGE") normalGEIdKey
1541 patGEName = libFun (fsLit "patGE") patGEIdKey
1544 bindSName = libFun (fsLit "bindS") bindSIdKey
1545 letSName = libFun (fsLit "letS") letSIdKey
1546 noBindSName = libFun (fsLit "noBindS") noBindSIdKey
1547 parSName = libFun (fsLit "parS") parSIdKey
1550 funDName = libFun (fsLit "funD") funDIdKey
1551 valDName = libFun (fsLit "valD") valDIdKey
1552 dataDName = libFun (fsLit "dataD") dataDIdKey
1553 newtypeDName = libFun (fsLit "newtypeD") newtypeDIdKey
1554 tySynDName = libFun (fsLit "tySynD") tySynDIdKey
1555 classDName = libFun (fsLit "classD") classDIdKey
1556 instanceDName = libFun (fsLit "instanceD") instanceDIdKey
1557 sigDName = libFun (fsLit "sigD") sigDIdKey
1558 forImpDName = libFun (fsLit "forImpD") forImpDIdKey
1561 cxtName = libFun (fsLit "cxt") cxtIdKey
1563 -- data Strict = ...
1564 isStrictName = libFun (fsLit "isStrict") isStrictKey
1565 notStrictName = libFun (fsLit "notStrict") notStrictKey
1568 normalCName = libFun (fsLit "normalC") normalCIdKey
1569 recCName = libFun (fsLit "recC") recCIdKey
1570 infixCName = libFun (fsLit "infixC") infixCIdKey
1571 forallCName = libFun (fsLit "forallC") forallCIdKey
1573 -- type StrictType = ...
1574 strictTypeName = libFun (fsLit "strictType") strictTKey
1576 -- type VarStrictType = ...
1577 varStrictTypeName = libFun (fsLit "varStrictType") varStrictTKey
1580 forallTName = libFun (fsLit "forallT") forallTIdKey
1581 varTName = libFun (fsLit "varT") varTIdKey
1582 conTName = libFun (fsLit "conT") conTIdKey
1583 tupleTName = libFun (fsLit "tupleT") tupleTIdKey
1584 arrowTName = libFun (fsLit "arrowT") arrowTIdKey
1585 listTName = libFun (fsLit "listT") listTIdKey
1586 appTName = libFun (fsLit "appT") appTIdKey
1588 -- data Callconv = ...
1589 cCallName = libFun (fsLit "cCall") cCallIdKey
1590 stdCallName = libFun (fsLit "stdCall") stdCallIdKey
1592 -- data Safety = ...
1593 unsafeName = libFun (fsLit "unsafe") unsafeIdKey
1594 safeName = libFun (fsLit "safe") safeIdKey
1595 threadsafeName = libFun (fsLit "threadsafe") threadsafeIdKey
1597 -- data FunDep = ...
1598 funDepName = libFun (fsLit "funDep") funDepIdKey
1600 matchQTyConName = libTc (fsLit "MatchQ") matchQTyConKey
1601 clauseQTyConName = libTc (fsLit "ClauseQ") clauseQTyConKey
1602 expQTyConName = libTc (fsLit "ExpQ") expQTyConKey
1603 stmtQTyConName = libTc (fsLit "StmtQ") stmtQTyConKey
1604 decQTyConName = libTc (fsLit "DecQ") decQTyConKey
1605 conQTyConName = libTc (fsLit "ConQ") conQTyConKey
1606 strictTypeQTyConName = libTc (fsLit "StrictTypeQ") strictTypeQTyConKey
1607 varStrictTypeQTyConName = libTc (fsLit "VarStrictTypeQ") varStrictTypeQTyConKey
1608 typeQTyConName = libTc (fsLit "TypeQ") typeQTyConKey
1609 fieldExpQTyConName = libTc (fsLit "FieldExpQ") fieldExpQTyConKey
1610 patQTyConName = libTc (fsLit "PatQ") patQTyConKey
1611 fieldPatQTyConName = libTc (fsLit "FieldPatQ") fieldPatQTyConKey
1614 quoteExpName = qqFun (fsLit "quoteExp") quoteExpKey
1615 quotePatName = qqFun (fsLit "quotePat") quotePatKey
1617 -- TyConUniques available: 100-129
1618 -- Check in PrelNames if you want to change this
1620 expTyConKey = mkPreludeTyConUnique 100
1621 matchTyConKey = mkPreludeTyConUnique 101
1622 clauseTyConKey = mkPreludeTyConUnique 102
1623 qTyConKey = mkPreludeTyConUnique 103
1624 expQTyConKey = mkPreludeTyConUnique 104
1625 decQTyConKey = mkPreludeTyConUnique 105
1626 patTyConKey = mkPreludeTyConUnique 106
1627 matchQTyConKey = mkPreludeTyConUnique 107
1628 clauseQTyConKey = mkPreludeTyConUnique 108
1629 stmtQTyConKey = mkPreludeTyConUnique 109
1630 conQTyConKey = mkPreludeTyConUnique 110
1631 typeQTyConKey = mkPreludeTyConUnique 111
1632 typeTyConKey = mkPreludeTyConUnique 112
1633 decTyConKey = mkPreludeTyConUnique 113
1634 varStrictTypeQTyConKey = mkPreludeTyConUnique 114
1635 strictTypeQTyConKey = mkPreludeTyConUnique 115
1636 fieldExpTyConKey = mkPreludeTyConUnique 116
1637 fieldPatTyConKey = mkPreludeTyConUnique 117
1638 nameTyConKey = mkPreludeTyConUnique 118
1639 patQTyConKey = mkPreludeTyConUnique 119
1640 fieldPatQTyConKey = mkPreludeTyConUnique 120
1641 fieldExpQTyConKey = mkPreludeTyConUnique 121
1642 funDepTyConKey = mkPreludeTyConUnique 122
1644 -- IdUniques available: 200-399
1645 -- If you want to change this, make sure you check in PrelNames
1647 returnQIdKey = mkPreludeMiscIdUnique 200
1648 bindQIdKey = mkPreludeMiscIdUnique 201
1649 sequenceQIdKey = mkPreludeMiscIdUnique 202
1650 liftIdKey = mkPreludeMiscIdUnique 203
1651 newNameIdKey = mkPreludeMiscIdUnique 204
1652 mkNameIdKey = mkPreludeMiscIdUnique 205
1653 mkNameG_vIdKey = mkPreludeMiscIdUnique 206
1654 mkNameG_dIdKey = mkPreludeMiscIdUnique 207
1655 mkNameG_tcIdKey = mkPreludeMiscIdUnique 208
1656 mkNameLIdKey = mkPreludeMiscIdUnique 209
1660 charLIdKey = mkPreludeMiscIdUnique 210
1661 stringLIdKey = mkPreludeMiscIdUnique 211
1662 integerLIdKey = mkPreludeMiscIdUnique 212
1663 intPrimLIdKey = mkPreludeMiscIdUnique 213
1664 wordPrimLIdKey = mkPreludeMiscIdUnique 214
1665 floatPrimLIdKey = mkPreludeMiscIdUnique 215
1666 doublePrimLIdKey = mkPreludeMiscIdUnique 216
1667 rationalLIdKey = mkPreludeMiscIdUnique 217
1670 litPIdKey = mkPreludeMiscIdUnique 220
1671 varPIdKey = mkPreludeMiscIdUnique 221
1672 tupPIdKey = mkPreludeMiscIdUnique 222
1673 conPIdKey = mkPreludeMiscIdUnique 223
1674 infixPIdKey = mkPreludeMiscIdUnique 312
1675 tildePIdKey = mkPreludeMiscIdUnique 224
1676 asPIdKey = mkPreludeMiscIdUnique 225
1677 wildPIdKey = mkPreludeMiscIdUnique 226
1678 recPIdKey = mkPreludeMiscIdUnique 227
1679 listPIdKey = mkPreludeMiscIdUnique 228
1680 sigPIdKey = mkPreludeMiscIdUnique 229
1682 -- type FieldPat = ...
1683 fieldPatIdKey = mkPreludeMiscIdUnique 230
1686 matchIdKey = mkPreludeMiscIdUnique 231
1688 -- data Clause = ...
1689 clauseIdKey = mkPreludeMiscIdUnique 232
1692 varEIdKey = mkPreludeMiscIdUnique 240
1693 conEIdKey = mkPreludeMiscIdUnique 241
1694 litEIdKey = mkPreludeMiscIdUnique 242
1695 appEIdKey = mkPreludeMiscIdUnique 243
1696 infixEIdKey = mkPreludeMiscIdUnique 244
1697 infixAppIdKey = mkPreludeMiscIdUnique 245
1698 sectionLIdKey = mkPreludeMiscIdUnique 246
1699 sectionRIdKey = mkPreludeMiscIdUnique 247
1700 lamEIdKey = mkPreludeMiscIdUnique 248
1701 tupEIdKey = mkPreludeMiscIdUnique 249
1702 condEIdKey = mkPreludeMiscIdUnique 250
1703 letEIdKey = mkPreludeMiscIdUnique 251
1704 caseEIdKey = mkPreludeMiscIdUnique 252
1705 doEIdKey = mkPreludeMiscIdUnique 253
1706 compEIdKey = mkPreludeMiscIdUnique 254
1707 fromEIdKey = mkPreludeMiscIdUnique 255
1708 fromThenEIdKey = mkPreludeMiscIdUnique 256
1709 fromToEIdKey = mkPreludeMiscIdUnique 257
1710 fromThenToEIdKey = mkPreludeMiscIdUnique 258
1711 listEIdKey = mkPreludeMiscIdUnique 259
1712 sigEIdKey = mkPreludeMiscIdUnique 260
1713 recConEIdKey = mkPreludeMiscIdUnique 261
1714 recUpdEIdKey = mkPreludeMiscIdUnique 262
1716 -- type FieldExp = ...
1717 fieldExpIdKey = mkPreludeMiscIdUnique 265
1720 guardedBIdKey = mkPreludeMiscIdUnique 266
1721 normalBIdKey = mkPreludeMiscIdUnique 267
1724 normalGEIdKey = mkPreludeMiscIdUnique 310
1725 patGEIdKey = mkPreludeMiscIdUnique 311
1728 bindSIdKey = mkPreludeMiscIdUnique 268
1729 letSIdKey = mkPreludeMiscIdUnique 269
1730 noBindSIdKey = mkPreludeMiscIdUnique 270
1731 parSIdKey = mkPreludeMiscIdUnique 271
1734 funDIdKey = mkPreludeMiscIdUnique 272
1735 valDIdKey = mkPreludeMiscIdUnique 273
1736 dataDIdKey = mkPreludeMiscIdUnique 274
1737 newtypeDIdKey = mkPreludeMiscIdUnique 275
1738 tySynDIdKey = mkPreludeMiscIdUnique 276
1739 classDIdKey = mkPreludeMiscIdUnique 277
1740 instanceDIdKey = mkPreludeMiscIdUnique 278
1741 sigDIdKey = mkPreludeMiscIdUnique 279
1742 forImpDIdKey = mkPreludeMiscIdUnique 297
1745 cxtIdKey = mkPreludeMiscIdUnique 280
1747 -- data Strict = ...
1748 isStrictKey = mkPreludeMiscIdUnique 281
1749 notStrictKey = mkPreludeMiscIdUnique 282
1752 normalCIdKey = mkPreludeMiscIdUnique 283
1753 recCIdKey = mkPreludeMiscIdUnique 284
1754 infixCIdKey = mkPreludeMiscIdUnique 285
1755 forallCIdKey = mkPreludeMiscIdUnique 288
1757 -- type StrictType = ...
1758 strictTKey = mkPreludeMiscIdUnique 286
1760 -- type VarStrictType = ...
1761 varStrictTKey = mkPreludeMiscIdUnique 287
1764 forallTIdKey = mkPreludeMiscIdUnique 290
1765 varTIdKey = mkPreludeMiscIdUnique 291
1766 conTIdKey = mkPreludeMiscIdUnique 292
1767 tupleTIdKey = mkPreludeMiscIdUnique 294
1768 arrowTIdKey = mkPreludeMiscIdUnique 295
1769 listTIdKey = mkPreludeMiscIdUnique 296
1770 appTIdKey = mkPreludeMiscIdUnique 293
1772 -- data Callconv = ...
1773 cCallIdKey = mkPreludeMiscIdUnique 300
1774 stdCallIdKey = mkPreludeMiscIdUnique 301
1776 -- data Safety = ...
1777 unsafeIdKey = mkPreludeMiscIdUnique 305
1778 safeIdKey = mkPreludeMiscIdUnique 306
1779 threadsafeIdKey = mkPreludeMiscIdUnique 307
1781 -- data FunDep = ...
1782 funDepIdKey = mkPreludeMiscIdUnique 320
1785 quoteExpKey = mkPreludeMiscIdUnique 321
1786 quotePatKey = mkPreludeMiscIdUnique 322