Add support for LINE pragma in template-haskell
[ghc.git] / libraries / template-haskell / Language / Haskell / TH / Lib.hs
1 -- |
2 -- TH.Lib contains lots of useful helper functions for
3 -- generating and manipulating Template Haskell terms
4
5 module Language.Haskell.TH.Lib where
6 -- All of the exports from this module should
7 -- be "public" functions. The main module TH
8 -- re-exports them all.
9
10 import Language.Haskell.TH.Syntax hiding (Role)
11 import qualified Language.Haskell.TH.Syntax as TH
12 import Control.Monad( liftM, liftM2 )
13 import Data.Word( Word8 )
14
15 ----------------------------------------------------------
16 -- * Type synonyms
17 ----------------------------------------------------------
18
19 type InfoQ = Q Info
20 type PatQ = Q Pat
21 type FieldPatQ = Q FieldPat
22 type ExpQ = Q Exp
23 type TExpQ a = Q (TExp a)
24 type DecQ = Q Dec
25 type DecsQ = Q [Dec]
26 type ConQ = Q Con
27 type TypeQ = Q Type
28 type TyLitQ = Q TyLit
29 type CxtQ = Q Cxt
30 type PredQ = Q Pred
31 type MatchQ = Q Match
32 type ClauseQ = Q Clause
33 type BodyQ = Q Body
34 type GuardQ = Q Guard
35 type StmtQ = Q Stmt
36 type RangeQ = Q Range
37 type StrictTypeQ = Q StrictType
38 type VarStrictTypeQ = Q VarStrictType
39 type FieldExpQ = Q FieldExp
40 type RuleBndrQ = Q RuleBndr
41 type TySynEqnQ = Q TySynEqn
42 type Role = TH.Role -- must be defined here for DsMeta to find it
43
44 ----------------------------------------------------------
45 -- * Lowercase pattern syntax functions
46 ----------------------------------------------------------
47
48 intPrimL :: Integer -> Lit
49 intPrimL = IntPrimL
50 wordPrimL :: Integer -> Lit
51 wordPrimL = WordPrimL
52 floatPrimL :: Rational -> Lit
53 floatPrimL = FloatPrimL
54 doublePrimL :: Rational -> Lit
55 doublePrimL = DoublePrimL
56 integerL :: Integer -> Lit
57 integerL = IntegerL
58 charL :: Char -> Lit
59 charL = CharL
60 stringL :: String -> Lit
61 stringL = StringL
62 stringPrimL :: [Word8] -> Lit
63 stringPrimL = StringPrimL
64 rationalL :: Rational -> Lit
65 rationalL = RationalL
66
67 litP :: Lit -> PatQ
68 litP l = return (LitP l)
69 varP :: Name -> PatQ
70 varP v = return (VarP v)
71 tupP :: [PatQ] -> PatQ
72 tupP ps = do { ps1 <- sequence ps; return (TupP ps1)}
73 unboxedTupP :: [PatQ] -> PatQ
74 unboxedTupP ps = do { ps1 <- sequence ps; return (UnboxedTupP ps1)}
75 conP :: Name -> [PatQ] -> PatQ
76 conP n ps = do ps' <- sequence ps
77 return (ConP n ps')
78 infixP :: PatQ -> Name -> PatQ -> PatQ
79 infixP p1 n p2 = do p1' <- p1
80 p2' <- p2
81 return (InfixP p1' n p2')
82 uInfixP :: PatQ -> Name -> PatQ -> PatQ
83 uInfixP p1 n p2 = do p1' <- p1
84 p2' <- p2
85 return (UInfixP p1' n p2')
86 parensP :: PatQ -> PatQ
87 parensP p = do p' <- p
88 return (ParensP p')
89
90 tildeP :: PatQ -> PatQ
91 tildeP p = do p' <- p
92 return (TildeP p')
93 bangP :: PatQ -> PatQ
94 bangP p = do p' <- p
95 return (BangP p')
96 asP :: Name -> PatQ -> PatQ
97 asP n p = do p' <- p
98 return (AsP n p')
99 wildP :: PatQ
100 wildP = return WildP
101 recP :: Name -> [FieldPatQ] -> PatQ
102 recP n fps = do fps' <- sequence fps
103 return (RecP n fps')
104 listP :: [PatQ] -> PatQ
105 listP ps = do ps' <- sequence ps
106 return (ListP ps')
107 sigP :: PatQ -> TypeQ -> PatQ
108 sigP p t = do p' <- p
109 t' <- t
110 return (SigP p' t')
111 viewP :: ExpQ -> PatQ -> PatQ
112 viewP e p = do e' <- e
113 p' <- p
114 return (ViewP e' p')
115
116 fieldPat :: Name -> PatQ -> FieldPatQ
117 fieldPat n p = do p' <- p
118 return (n, p')
119
120
121 -------------------------------------------------------------------------------
122 -- * Stmt
123
124 bindS :: PatQ -> ExpQ -> StmtQ
125 bindS p e = liftM2 BindS p e
126
127 letS :: [DecQ] -> StmtQ
128 letS ds = do { ds1 <- sequence ds; return (LetS ds1) }
129
130 noBindS :: ExpQ -> StmtQ
131 noBindS e = do { e1 <- e; return (NoBindS e1) }
132
133 parS :: [[StmtQ]] -> StmtQ
134 parS sss = do { sss1 <- mapM sequence sss; return (ParS sss1) }
135
136 -------------------------------------------------------------------------------
137 -- * Range
138
139 fromR :: ExpQ -> RangeQ
140 fromR x = do { a <- x; return (FromR a) }
141
142 fromThenR :: ExpQ -> ExpQ -> RangeQ
143 fromThenR x y = do { a <- x; b <- y; return (FromThenR a b) }
144
145 fromToR :: ExpQ -> ExpQ -> RangeQ
146 fromToR x y = do { a <- x; b <- y; return (FromToR a b) }
147
148 fromThenToR :: ExpQ -> ExpQ -> ExpQ -> RangeQ
149 fromThenToR x y z = do { a <- x; b <- y; c <- z;
150 return (FromThenToR a b c) }
151 -------------------------------------------------------------------------------
152 -- * Body
153
154 normalB :: ExpQ -> BodyQ
155 normalB e = do { e1 <- e; return (NormalB e1) }
156
157 guardedB :: [Q (Guard,Exp)] -> BodyQ
158 guardedB ges = do { ges' <- sequence ges; return (GuardedB ges') }
159
160 -------------------------------------------------------------------------------
161 -- * Guard
162
163 normalG :: ExpQ -> GuardQ
164 normalG e = do { e1 <- e; return (NormalG e1) }
165
166 normalGE :: ExpQ -> ExpQ -> Q (Guard, Exp)
167 normalGE g e = do { g1 <- g; e1 <- e; return (NormalG g1, e1) }
168
169 patG :: [StmtQ] -> GuardQ
170 patG ss = do { ss' <- sequence ss; return (PatG ss') }
171
172 patGE :: [StmtQ] -> ExpQ -> Q (Guard, Exp)
173 patGE ss e = do { ss' <- sequence ss;
174 e' <- e;
175 return (PatG ss', e') }
176
177 -------------------------------------------------------------------------------
178 -- * Match and Clause
179
180 -- | Use with 'caseE'
181 match :: PatQ -> BodyQ -> [DecQ] -> MatchQ
182 match p rhs ds = do { p' <- p;
183 r' <- rhs;
184 ds' <- sequence ds;
185 return (Match p' r' ds') }
186
187 -- | Use with 'funD'
188 clause :: [PatQ] -> BodyQ -> [DecQ] -> ClauseQ
189 clause ps r ds = do { ps' <- sequence ps;
190 r' <- r;
191 ds' <- sequence ds;
192 return (Clause ps' r' ds') }
193
194
195 ---------------------------------------------------------------------------
196 -- * Exp
197
198 -- | Dynamically binding a variable (unhygenic)
199 dyn :: String -> ExpQ
200 dyn s = return (VarE (mkName s))
201
202 global :: Name -> ExpQ
203 {-# DEPRECATED global "Use varE instead" #-}
204 -- Trac #8656; I have no idea why this function is duplicated
205 global s = return (VarE s)
206
207 varE :: Name -> ExpQ
208 varE s = return (VarE s)
209
210 conE :: Name -> ExpQ
211 conE s = return (ConE s)
212
213 litE :: Lit -> ExpQ
214 litE c = return (LitE c)
215
216 appE :: ExpQ -> ExpQ -> ExpQ
217 appE x y = do { a <- x; b <- y; return (AppE a b)}
218
219 parensE :: ExpQ -> ExpQ
220 parensE x = do { x' <- x; return (ParensE x') }
221
222 uInfixE :: ExpQ -> ExpQ -> ExpQ -> ExpQ
223 uInfixE x s y = do { x' <- x; s' <- s; y' <- y;
224 return (UInfixE x' s' y') }
225
226 infixE :: Maybe ExpQ -> ExpQ -> Maybe ExpQ -> ExpQ
227 infixE (Just x) s (Just y) = do { a <- x; s' <- s; b <- y;
228 return (InfixE (Just a) s' (Just b))}
229 infixE Nothing s (Just y) = do { s' <- s; b <- y;
230 return (InfixE Nothing s' (Just b))}
231 infixE (Just x) s Nothing = do { a <- x; s' <- s;
232 return (InfixE (Just a) s' Nothing)}
233 infixE Nothing s Nothing = do { s' <- s; return (InfixE Nothing s' Nothing) }
234
235 infixApp :: ExpQ -> ExpQ -> ExpQ -> ExpQ
236 infixApp x y z = infixE (Just x) y (Just z)
237 sectionL :: ExpQ -> ExpQ -> ExpQ
238 sectionL x y = infixE (Just x) y Nothing
239 sectionR :: ExpQ -> ExpQ -> ExpQ
240 sectionR x y = infixE Nothing x (Just y)
241
242 lamE :: [PatQ] -> ExpQ -> ExpQ
243 lamE ps e = do ps' <- sequence ps
244 e' <- e
245 return (LamE ps' e')
246
247 -- | Single-arg lambda
248 lam1E :: PatQ -> ExpQ -> ExpQ
249 lam1E p e = lamE [p] e
250
251 lamCaseE :: [MatchQ] -> ExpQ
252 lamCaseE ms = sequence ms >>= return . LamCaseE
253
254 tupE :: [ExpQ] -> ExpQ
255 tupE es = do { es1 <- sequence es; return (TupE es1)}
256
257 unboxedTupE :: [ExpQ] -> ExpQ
258 unboxedTupE es = do { es1 <- sequence es; return (UnboxedTupE es1)}
259
260 condE :: ExpQ -> ExpQ -> ExpQ -> ExpQ
261 condE x y z = do { a <- x; b <- y; c <- z; return (CondE a b c)}
262
263 multiIfE :: [Q (Guard, Exp)] -> ExpQ
264 multiIfE alts = sequence alts >>= return . MultiIfE
265
266 letE :: [DecQ] -> ExpQ -> ExpQ
267 letE ds e = do { ds2 <- sequence ds; e2 <- e; return (LetE ds2 e2) }
268
269 caseE :: ExpQ -> [MatchQ] -> ExpQ
270 caseE e ms = do { e1 <- e; ms1 <- sequence ms; return (CaseE e1 ms1) }
271
272 doE :: [StmtQ] -> ExpQ
273 doE ss = do { ss1 <- sequence ss; return (DoE ss1) }
274
275 compE :: [StmtQ] -> ExpQ
276 compE ss = do { ss1 <- sequence ss; return (CompE ss1) }
277
278 arithSeqE :: RangeQ -> ExpQ
279 arithSeqE r = do { r' <- r; return (ArithSeqE r') }
280
281 listE :: [ExpQ] -> ExpQ
282 listE es = do { es1 <- sequence es; return (ListE es1) }
283
284 sigE :: ExpQ -> TypeQ -> ExpQ
285 sigE e t = do { e1 <- e; t1 <- t; return (SigE e1 t1) }
286
287 recConE :: Name -> [Q (Name,Exp)] -> ExpQ
288 recConE c fs = do { flds <- sequence fs; return (RecConE c flds) }
289
290 recUpdE :: ExpQ -> [Q (Name,Exp)] -> ExpQ
291 recUpdE e fs = do { e1 <- e; flds <- sequence fs; return (RecUpdE e1 flds) }
292
293 stringE :: String -> ExpQ
294 stringE = litE . stringL
295
296 fieldExp :: Name -> ExpQ -> Q (Name, Exp)
297 fieldExp s e = do { e' <- e; return (s,e') }
298
299 -- ** 'arithSeqE' Shortcuts
300 fromE :: ExpQ -> ExpQ
301 fromE x = do { a <- x; return (ArithSeqE (FromR a)) }
302
303 fromThenE :: ExpQ -> ExpQ -> ExpQ
304 fromThenE x y = do { a <- x; b <- y; return (ArithSeqE (FromThenR a b)) }
305
306 fromToE :: ExpQ -> ExpQ -> ExpQ
307 fromToE x y = do { a <- x; b <- y; return (ArithSeqE (FromToR a b)) }
308
309 fromThenToE :: ExpQ -> ExpQ -> ExpQ -> ExpQ
310 fromThenToE x y z = do { a <- x; b <- y; c <- z;
311 return (ArithSeqE (FromThenToR a b c)) }
312
313
314 -------------------------------------------------------------------------------
315 -- * Dec
316
317 valD :: PatQ -> BodyQ -> [DecQ] -> DecQ
318 valD p b ds =
319 do { p' <- p
320 ; ds' <- sequence ds
321 ; b' <- b
322 ; return (ValD p' b' ds')
323 }
324
325 funD :: Name -> [ClauseQ] -> DecQ
326 funD nm cs =
327 do { cs1 <- sequence cs
328 ; return (FunD nm cs1)
329 }
330
331 tySynD :: Name -> [TyVarBndr] -> TypeQ -> DecQ
332 tySynD tc tvs rhs = do { rhs1 <- rhs; return (TySynD tc tvs rhs1) }
333
334 dataD :: CxtQ -> Name -> [TyVarBndr] -> [ConQ] -> [Name] -> DecQ
335 dataD ctxt tc tvs cons derivs =
336 do
337 ctxt1 <- ctxt
338 cons1 <- sequence cons
339 return (DataD ctxt1 tc tvs cons1 derivs)
340
341 newtypeD :: CxtQ -> Name -> [TyVarBndr] -> ConQ -> [Name] -> DecQ
342 newtypeD ctxt tc tvs con derivs =
343 do
344 ctxt1 <- ctxt
345 con1 <- con
346 return (NewtypeD ctxt1 tc tvs con1 derivs)
347
348 classD :: CxtQ -> Name -> [TyVarBndr] -> [FunDep] -> [DecQ] -> DecQ
349 classD ctxt cls tvs fds decs =
350 do
351 decs1 <- sequence decs
352 ctxt1 <- ctxt
353 return $ ClassD ctxt1 cls tvs fds decs1
354
355 instanceD :: CxtQ -> TypeQ -> [DecQ] -> DecQ
356 instanceD ctxt ty decs =
357 do
358 ctxt1 <- ctxt
359 decs1 <- sequence decs
360 ty1 <- ty
361 return $ InstanceD ctxt1 ty1 decs1
362
363 sigD :: Name -> TypeQ -> DecQ
364 sigD fun ty = liftM (SigD fun) $ ty
365
366 forImpD :: Callconv -> Safety -> String -> Name -> TypeQ -> DecQ
367 forImpD cc s str n ty
368 = do ty' <- ty
369 return $ ForeignD (ImportF cc s str n ty')
370
371 infixLD :: Int -> Name -> DecQ
372 infixLD prec nm = return (InfixD (Fixity prec InfixL) nm)
373
374 infixRD :: Int -> Name -> DecQ
375 infixRD prec nm = return (InfixD (Fixity prec InfixR) nm)
376
377 infixND :: Int -> Name -> DecQ
378 infixND prec nm = return (InfixD (Fixity prec InfixN) nm)
379
380 pragInlD :: Name -> Inline -> RuleMatch -> Phases -> DecQ
381 pragInlD name inline rm phases
382 = return $ PragmaD $ InlineP name inline rm phases
383
384 pragSpecD :: Name -> TypeQ -> Phases -> DecQ
385 pragSpecD n ty phases
386 = do
387 ty1 <- ty
388 return $ PragmaD $ SpecialiseP n ty1 Nothing phases
389
390 pragSpecInlD :: Name -> TypeQ -> Inline -> Phases -> DecQ
391 pragSpecInlD n ty inline phases
392 = do
393 ty1 <- ty
394 return $ PragmaD $ SpecialiseP n ty1 (Just inline) phases
395
396 pragSpecInstD :: TypeQ -> DecQ
397 pragSpecInstD ty
398 = do
399 ty1 <- ty
400 return $ PragmaD $ SpecialiseInstP ty1
401
402 pragRuleD :: String -> [RuleBndrQ] -> ExpQ -> ExpQ -> Phases -> DecQ
403 pragRuleD n bndrs lhs rhs phases
404 = do
405 bndrs1 <- sequence bndrs
406 lhs1 <- lhs
407 rhs1 <- rhs
408 return $ PragmaD $ RuleP n bndrs1 lhs1 rhs1 phases
409
410 pragAnnD :: AnnTarget -> ExpQ -> DecQ
411 pragAnnD target expr
412 = do
413 exp1 <- expr
414 return $ PragmaD $ AnnP target exp1
415
416 pragLineD :: Int -> String -> DecQ
417 pragLineD line file = return $ PragmaD $ LineP line file
418
419 familyNoKindD :: FamFlavour -> Name -> [TyVarBndr] -> DecQ
420 familyNoKindD flav tc tvs = return $ FamilyD flav tc tvs Nothing
421
422 familyKindD :: FamFlavour -> Name -> [TyVarBndr] -> Kind -> DecQ
423 familyKindD flav tc tvs k = return $ FamilyD flav tc tvs (Just k)
424
425 dataInstD :: CxtQ -> Name -> [TypeQ] -> [ConQ] -> [Name] -> DecQ
426 dataInstD ctxt tc tys cons derivs =
427 do
428 ctxt1 <- ctxt
429 tys1 <- sequence tys
430 cons1 <- sequence cons
431 return (DataInstD ctxt1 tc tys1 cons1 derivs)
432
433 newtypeInstD :: CxtQ -> Name -> [TypeQ] -> ConQ -> [Name] -> DecQ
434 newtypeInstD ctxt tc tys con derivs =
435 do
436 ctxt1 <- ctxt
437 tys1 <- sequence tys
438 con1 <- con
439 return (NewtypeInstD ctxt1 tc tys1 con1 derivs)
440
441 tySynInstD :: Name -> TySynEqnQ -> DecQ
442 tySynInstD tc eqn =
443 do
444 eqn1 <- eqn
445 return (TySynInstD tc eqn1)
446
447 closedTypeFamilyNoKindD :: Name -> [TyVarBndr] -> [TySynEqnQ] -> DecQ
448 closedTypeFamilyNoKindD tc tvs eqns =
449 do
450 eqns1 <- sequence eqns
451 return (ClosedTypeFamilyD tc tvs Nothing eqns1)
452
453 closedTypeFamilyKindD :: Name -> [TyVarBndr] -> Kind -> [TySynEqnQ] -> DecQ
454 closedTypeFamilyKindD tc tvs kind eqns =
455 do
456 eqns1 <- sequence eqns
457 return (ClosedTypeFamilyD tc tvs (Just kind) eqns1)
458
459 roleAnnotD :: Name -> [Role] -> DecQ
460 roleAnnotD name roles = return $ RoleAnnotD name roles
461
462 tySynEqn :: [TypeQ] -> TypeQ -> TySynEqnQ
463 tySynEqn lhs rhs =
464 do
465 lhs1 <- sequence lhs
466 rhs1 <- rhs
467 return (TySynEqn lhs1 rhs1)
468
469 cxt :: [PredQ] -> CxtQ
470 cxt = sequence
471
472 normalC :: Name -> [StrictTypeQ] -> ConQ
473 normalC con strtys = liftM (NormalC con) $ sequence strtys
474
475 recC :: Name -> [VarStrictTypeQ] -> ConQ
476 recC con varstrtys = liftM (RecC con) $ sequence varstrtys
477
478 infixC :: Q (Strict, Type) -> Name -> Q (Strict, Type) -> ConQ
479 infixC st1 con st2 = do st1' <- st1
480 st2' <- st2
481 return $ InfixC st1' con st2'
482
483 forallC :: [TyVarBndr] -> CxtQ -> ConQ -> ConQ
484 forallC ns ctxt con = liftM2 (ForallC ns) ctxt con
485
486
487 -------------------------------------------------------------------------------
488 -- * Type
489
490 forallT :: [TyVarBndr] -> CxtQ -> TypeQ -> TypeQ
491 forallT tvars ctxt ty = do
492 ctxt1 <- ctxt
493 ty1 <- ty
494 return $ ForallT tvars ctxt1 ty1
495
496 varT :: Name -> TypeQ
497 varT = return . VarT
498
499 conT :: Name -> TypeQ
500 conT = return . ConT
501
502 appT :: TypeQ -> TypeQ -> TypeQ
503 appT t1 t2 = do
504 t1' <- t1
505 t2' <- t2
506 return $ AppT t1' t2'
507
508 arrowT :: TypeQ
509 arrowT = return ArrowT
510
511 listT :: TypeQ
512 listT = return ListT
513
514 litT :: TyLitQ -> TypeQ
515 litT l = fmap LitT l
516
517 tupleT :: Int -> TypeQ
518 tupleT i = return (TupleT i)
519
520 unboxedTupleT :: Int -> TypeQ
521 unboxedTupleT i = return (UnboxedTupleT i)
522
523 sigT :: TypeQ -> Kind -> TypeQ
524 sigT t k
525 = do
526 t' <- t
527 return $ SigT t' k
528
529 equalityT :: TypeQ
530 equalityT = return EqualityT
531
532 {-# DEPRECATED classP "As of template-haskell-2.10, constraint predicates (Pred) are just types (Type), in keeping with ConstraintKinds. Please use 'conT' and 'appT'." #-}
533 classP :: Name -> [Q Type] -> Q Pred
534 classP cla tys
535 = do
536 tysl <- sequence tys
537 return (foldl AppT (ConT cla) tysl)
538
539 {-# DEPRECATED equalP "As of template-haskell-2.10, constraint predicates (Pred) are just types (Type), in keeping with ConstraintKinds. Please see 'equalityT'." #-}
540 equalP :: TypeQ -> TypeQ -> PredQ
541 equalP tleft tright
542 = do
543 tleft1 <- tleft
544 tright1 <- tright
545 eqT <- equalityT
546 return (foldl AppT eqT [tleft1, tright1])
547
548 promotedT :: Name -> TypeQ
549 promotedT = return . PromotedT
550
551 promotedTupleT :: Int -> TypeQ
552 promotedTupleT i = return (PromotedTupleT i)
553
554 promotedNilT :: TypeQ
555 promotedNilT = return PromotedNilT
556
557 promotedConsT :: TypeQ
558 promotedConsT = return PromotedConsT
559
560 isStrict, notStrict, unpacked :: Q Strict
561 isStrict = return $ IsStrict
562 notStrict = return $ NotStrict
563 unpacked = return Unpacked
564
565 strictType :: Q Strict -> TypeQ -> StrictTypeQ
566 strictType = liftM2 (,)
567
568 varStrictType :: Name -> StrictTypeQ -> VarStrictTypeQ
569 varStrictType v st = do (s, t) <- st
570 return (v, s, t)
571
572 -- * Type Literals
573
574 numTyLit :: Integer -> TyLitQ
575 numTyLit n = if n >= 0 then return (NumTyLit n)
576 else fail ("Negative type-level number: " ++ show n)
577
578 strTyLit :: String -> TyLitQ
579 strTyLit s = return (StrTyLit s)
580
581
582
583 -------------------------------------------------------------------------------
584 -- * Kind
585
586 plainTV :: Name -> TyVarBndr
587 plainTV = PlainTV
588
589 kindedTV :: Name -> Kind -> TyVarBndr
590 kindedTV = KindedTV
591
592 varK :: Name -> Kind
593 varK = VarT
594
595 conK :: Name -> Kind
596 conK = ConT
597
598 tupleK :: Int -> Kind
599 tupleK = TupleT
600
601 arrowK :: Kind
602 arrowK = ArrowT
603
604 listK :: Kind
605 listK = ListT
606
607 appK :: Kind -> Kind -> Kind
608 appK = AppT
609
610 starK :: Kind
611 starK = StarT
612
613 constraintK :: Kind
614 constraintK = ConstraintT
615
616 -------------------------------------------------------------------------------
617 -- * Role
618
619 nominalR, representationalR, phantomR, inferR :: Role
620 nominalR = NominalR
621 representationalR = RepresentationalR
622 phantomR = PhantomR
623 inferR = InferR
624
625 -------------------------------------------------------------------------------
626 -- * Callconv
627
628 cCall, stdCall :: Callconv
629 cCall = CCall
630 stdCall = StdCall
631
632 -------------------------------------------------------------------------------
633 -- * Safety
634
635 unsafe, safe, interruptible :: Safety
636 unsafe = Unsafe
637 safe = Safe
638 interruptible = Interruptible
639
640 -------------------------------------------------------------------------------
641 -- * FunDep
642
643 funDep :: [Name] -> [Name] -> FunDep
644 funDep = FunDep
645
646 -------------------------------------------------------------------------------
647 -- * FamFlavour
648
649 typeFam, dataFam :: FamFlavour
650 typeFam = TypeFam
651 dataFam = DataFam
652
653 -------------------------------------------------------------------------------
654 -- * RuleBndr
655 ruleVar :: Name -> RuleBndrQ
656 ruleVar = return . RuleVar
657
658 typedRuleVar :: Name -> TypeQ -> RuleBndrQ
659 typedRuleVar n ty = ty >>= return . TypedRuleVar n
660
661 --------------------------------------------------------------
662 -- * Useful helper function
663
664 appsE :: [ExpQ] -> ExpQ
665 appsE [] = error "appsE []"
666 appsE [x] = x
667 appsE (x:y:zs) = appsE ( (appE x y) : zs )
668
669 -- | Return the Module at the place of splicing. Can be used as an
670 -- input for 'reifyModule'.
671 thisModule :: Q Module
672 thisModule = do
673 loc <- location
674 return $ Module (mkPkgName $ loc_package loc) (mkModName $ loc_module loc)