2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[TcGenDeriv]{Generating derived instance declarations}
6 This module is nominally ``subordinate'' to @TcDeriv@, which is the
7 ``official'' interface to deriving-related things.
9 This is where we do all the grimy bindings' generation.
21 gen_tag_n_con_monobind,
23 con2tag_RDR, tag2con_RDR, maxtag_RDR,
28 #include "HsVersions.h"
30 import HsSyn ( Pat(..), HsConDetails(..), HsExpr(..), MonoBinds(..),
31 Match(..), GRHSs(..), Stmt(..), HsLit(..),
32 HsBinds(..), HsType(..), HsStmtContext(..),
33 unguardedRHS, mkSimpleMatch, mkMonoBind, andMonoBindList, placeHolderType
35 import RdrName ( RdrName, mkUnqual, nameRdrName, getRdrName )
36 import RdrHsSyn ( mkHsOpApp, RdrNameMonoBinds, RdrNameHsExpr, RdrNamePat, mkHsDo )
37 import BasicTypes ( RecFlag(..), Fixity(..), FixityDirection(..)
41 import FieldLabel ( fieldLabelName )
42 import DataCon ( isNullaryDataCon, dataConTag,
43 dataConOrigArgTys, dataConSourceArity, fIRST_TAG,
46 import Name ( getOccString, getOccName, getSrcLoc, occNameString,
47 occNameUserString, varName,
49 isDataSymOcc, isSymOcc
52 import HscTypes ( FixityEnv, lookupFixity )
53 import PrelNames -- Lots of Names
54 import PrimOp -- Lots of Names
55 import SrcLoc ( generatedSrcLoc, SrcLoc )
56 import TyCon ( TyCon, isNewTyCon, tyConDataCons, isEnumerationTyCon,
57 maybeTyConSingleCon, tyConFamilySize, tyConTyVars
59 import TcType ( isUnLiftedType, tcEqType, Type )
60 import TysPrim ( charPrimTy, intPrimTy, wordPrimTy, addrPrimTy,
61 floatPrimTy, doublePrimTy
63 import Util ( zipWithEqual, isSingleton,
64 zipWith3Equal, nOfThem, zipEqual )
65 import Panic ( panic, assertPanic )
66 import Char ( ord, isAlpha )
68 import List ( partition, intersperse )
74 %************************************************************************
76 \subsection{Generating code, by derivable class}
78 %************************************************************************
80 %************************************************************************
82 \subsubsection{Generating @Eq@ instance declarations}
84 %************************************************************************
86 Here are the heuristics for the code we generate for @Eq@:
89 Let's assume we have a data type with some (possibly zero) nullary
90 data constructors and some ordinary, non-nullary ones (the rest,
91 also possibly zero of them). Here's an example, with both \tr{N}ullary
92 and \tr{O}rdinary data cons.
94 data Foo ... = N1 | N2 ... | Nn | O1 a b | O2 Int | O3 Double b b | ...
98 For the ordinary constructors (if any), we emit clauses to do The
102 (==) (O1 a1 b1) (O1 a2 b2) = a1 == a2 && b1 == b2
103 (==) (O2 a1) (O2 a2) = a1 == a2
104 (==) (O3 a1 b1 c1) (O3 a2 b2 c2) = a1 == a2 && b1 == b2 && c1 == c2
107 Note: if we're comparing unlifted things, e.g., if \tr{a1} and
108 \tr{a2} are \tr{Float#}s, then we have to generate
110 case (a1 `eqFloat#` a2) of
113 for that particular test.
116 If there are any nullary constructors, we emit a catch-all clause of
120 (==) a b = case (con2tag_Foo a) of { a# ->
121 case (con2tag_Foo b) of { b# ->
122 case (a# ==# b#) of {
127 If there aren't any nullary constructors, we emit a simpler
134 For the @(/=)@ method, we normally just use the default method.
136 If the type is an enumeration type, we could/may/should? generate
137 special code that calls @con2tag_Foo@, much like for @(==)@ shown
141 We thought about doing this: If we're also deriving @Ord@ for this
144 instance ... Eq (Foo ...) where
145 (==) a b = case (compare a b) of { _LT -> False; _EQ -> True ; _GT -> False}
146 (/=) a b = case (compare a b) of { _LT -> True ; _EQ -> False; _GT -> True }
148 However, that requires that \tr{Ord <whatever>} was put in the context
149 for the instance decl, which it probably wasn't, so the decls
150 produced don't get through the typechecker.
154 deriveEq :: RdrName -- Class
155 -> RdrName -- Type constructor
156 -> [ (RdrName, [RdrType]) ] -- Constructors
157 -> (RdrContext, -- Context for the inst decl
158 [RdrBind], -- Binds in the inst decl
159 [RdrBind]) -- Extra value bindings outside
161 deriveEq clas tycon constrs
162 = (context, [eq_bind, ne_bind], [])
164 context = [(clas, [ty]) | (_, tys) <- constrs, ty <- tys]
167 (nullary_cons, non_nullary_cons) = partition is_nullary constrs
168 is_nullary (_, args) = null args
171 gen_Eq_binds :: TyCon -> RdrNameMonoBinds
175 tycon_loc = getSrcLoc tycon
176 (nullary_cons, nonnullary_cons)
177 | isNewTyCon tycon = ([], tyConDataCons tycon)
178 | otherwise = partition isNullaryDataCon (tyConDataCons tycon)
181 = if (null nullary_cons) then
182 case maybeTyConSingleCon tycon of
184 Nothing -> -- if cons don't match, then False
185 [([wildPat, wildPat], false_Expr)]
186 else -- calc. and compare the tags
188 untag_Expr tycon [(a_RDR,ah_RDR), (b_RDR,bh_RDR)]
189 (genOpApp (HsVar ah_RDR) eqInt_RDR (HsVar bh_RDR)))]
191 mk_FunMonoBind tycon_loc eq_RDR ((map pats_etc nonnullary_cons) ++ rest)
193 mk_easy_FunMonoBind tycon_loc ne_RDR [a_Pat, b_Pat] [] (
194 HsApp (HsVar not_RDR) (HsPar (mkHsVarApps eq_RDR [a_RDR, b_RDR])))
196 ------------------------------------------------------------------
199 con1_pat = mkConPat data_con_RDR as_needed
200 con2_pat = mkConPat data_con_RDR bs_needed
202 data_con_RDR = getRdrName data_con
203 con_arity = length tys_needed
204 as_needed = take con_arity as_RDRs
205 bs_needed = take con_arity bs_RDRs
206 tys_needed = dataConOrigArgTys data_con
208 ([con1_pat, con2_pat], nested_eq_expr tys_needed as_needed bs_needed)
210 nested_eq_expr [] [] [] = true_Expr
211 nested_eq_expr tys as bs
212 = foldl1 and_Expr (zipWith3Equal "nested_eq" nested_eq tys as bs)
214 nested_eq ty a b = HsPar (eq_Expr ty (HsVar a) (HsVar b))
217 %************************************************************************
219 \subsubsection{Generating @Ord@ instance declarations}
221 %************************************************************************
223 For a derived @Ord@, we concentrate our attentions on @compare@
225 compare :: a -> a -> Ordering
226 data Ordering = LT | EQ | GT deriving ()
229 We will use the same example data type as above:
231 data Foo ... = N1 | N2 ... | Nn | O1 a b | O2 Int | O3 Double b b | ...
236 We do all the other @Ord@ methods with calls to @compare@:
238 instance ... (Ord <wurble> <wurble>) where
239 a < b = case (compare a b) of { LT -> True; EQ -> False; GT -> False }
240 a <= b = case (compare a b) of { LT -> True; EQ -> True; GT -> False }
241 a >= b = case (compare a b) of { LT -> False; EQ -> True; GT -> True }
242 a > b = case (compare a b) of { LT -> False; EQ -> False; GT -> True }
244 max a b = case (compare a b) of { LT -> b; EQ -> a; GT -> a }
245 min a b = case (compare a b) of { LT -> a; EQ -> b; GT -> b }
247 -- compare to come...
251 @compare@ always has two parts. First, we use the compared
252 data-constructors' tags to deal with the case of different
255 compare a b = case (con2tag_Foo a) of { a# ->
256 case (con2tag_Foo b) of { b# ->
257 case (a# ==# b#) of {
259 False -> case (a# <# b#) of
264 cmp_eq = ... to come ...
268 We are only left with the ``help'' function @cmp_eq@, to deal with
269 comparing data constructors with the same tag.
271 For the ordinary constructors (if any), we emit the sorta-obvious
272 compare-style stuff; for our example:
274 cmp_eq (O1 a1 b1) (O1 a2 b2)
275 = case (compare a1 a2) of { LT -> LT; EQ -> compare b1 b2; GT -> GT }
277 cmp_eq (O2 a1) (O2 a2)
280 cmp_eq (O3 a1 b1 c1) (O3 a2 b2 c2)
281 = case (compare a1 a2) of {
284 EQ -> case compare b1 b2 of {
292 Again, we must be careful about unlifted comparisons. For example,
293 if \tr{a1} and \tr{a2} were \tr{Int#}s in the 2nd example above, we'd need to
297 cmp_eq lt eq gt (O2 a1) (O2 a2)
299 -- or maybe the unfolded equivalent
303 For the remaining nullary constructors, we already know that the
310 If there is only one constructor in the Data Type we don't need the WildCard Pattern.
314 gen_Ord_binds :: TyCon -> RdrNameMonoBinds
317 = compare -- `AndMonoBinds` compare
318 -- The default declaration in PrelBase handles this
320 tycon_loc = getSrcLoc tycon
321 --------------------------------------------------------------------
322 compare = mk_easy_FunMonoBind tycon_loc compare_RDR
323 [a_Pat, b_Pat] [cmp_eq] compare_rhs
325 | single_con_type = cmp_eq_Expr a_Expr b_Expr
327 = untag_Expr tycon [(a_RDR, ah_RDR), (b_RDR, bh_RDR)]
328 (cmp_tags_Expr eqInt_RDR ah_RDR bh_RDR
329 (cmp_eq_Expr a_Expr b_Expr) -- True case
330 -- False case; they aren't equal
331 -- So we need to do a less-than comparison on the tags
332 (cmp_tags_Expr ltInt_RDR ah_RDR bh_RDR ltTag_Expr gtTag_Expr))
334 tycon_data_cons = tyConDataCons tycon
335 single_con_type = isSingleton tycon_data_cons
336 (nullary_cons, nonnullary_cons)
337 | isNewTyCon tycon = ([], tyConDataCons tycon)
338 | otherwise = partition isNullaryDataCon tycon_data_cons
340 cmp_eq = mk_FunMonoBind tycon_loc cmp_eq_RDR cmp_eq_match
342 | isEnumerationTyCon tycon
343 -- We know the tags are equal, so if it's an enumeration TyCon,
344 -- then there is nothing left to do
345 -- Catch this specially to avoid warnings
346 -- about overlapping patterns from the desugarer,
347 -- and to avoid unnecessary pattern-matching
348 = [([wildPat,wildPat], eqTag_Expr)]
350 = map pats_etc nonnullary_cons ++
351 (if single_con_type then -- Omit wildcards when there's just one
352 [] -- constructor, to silence desugarer
354 [([wildPat, wildPat], default_rhs)])
358 = ([con1_pat, con2_pat],
359 nested_compare_expr tys_needed as_needed bs_needed)
361 con1_pat = mkConPat data_con_RDR as_needed
362 con2_pat = mkConPat data_con_RDR bs_needed
364 data_con_RDR = getRdrName data_con
365 con_arity = length tys_needed
366 as_needed = take con_arity as_RDRs
367 bs_needed = take con_arity bs_RDRs
368 tys_needed = dataConOrigArgTys data_con
370 nested_compare_expr [ty] [a] [b]
371 = careful_compare_Case ty eqTag_Expr (HsVar a) (HsVar b)
373 nested_compare_expr (ty:tys) (a:as) (b:bs)
374 = let eq_expr = nested_compare_expr tys as bs
375 in careful_compare_Case ty eq_expr (HsVar a) (HsVar b)
377 default_rhs | null nullary_cons = impossible_Expr -- Keep desugarer from complaining about
378 -- inexhaustive patterns
379 | otherwise = eqTag_Expr -- Some nullary constructors;
380 -- Tags are equal, no args => return EQ
383 %************************************************************************
385 \subsubsection{Generating @Enum@ instance declarations}
387 %************************************************************************
389 @Enum@ can only be derived for enumeration types. For a type
391 data Foo ... = N1 | N2 | ... | Nn
394 we use both @con2tag_Foo@ and @tag2con_Foo@ functions, as well as a
395 @maxtag_Foo@ variable (all generated by @gen_tag_n_con_binds@).
398 instance ... Enum (Foo ...) where
399 succ x = toEnum (1 + fromEnum x)
400 pred x = toEnum (fromEnum x - 1)
402 toEnum i = tag2con_Foo i
404 enumFrom a = map tag2con_Foo [con2tag_Foo a .. maxtag_Foo]
408 = case con2tag_Foo a of
409 a# -> map tag2con_Foo (enumFromTo (I# a#) maxtag_Foo)
412 = map tag2con_Foo [con2tag_Foo a, con2tag_Foo b .. maxtag_Foo]
416 = case con2tag_Foo a of { a# ->
417 case con2tag_Foo b of { b# ->
418 map tag2con_Foo (enumFromThenTo (I# a#) (I# b#) maxtag_Foo)
422 For @enumFromTo@ and @enumFromThenTo@, we use the default methods.
425 gen_Enum_binds :: TyCon -> RdrNameMonoBinds
428 = succ_enum `AndMonoBinds`
429 pred_enum `AndMonoBinds`
430 to_enum `AndMonoBinds`
431 enum_from `AndMonoBinds`
432 enum_from_then `AndMonoBinds`
435 tycon_loc = getSrcLoc tycon
436 occ_nm = getOccString tycon
439 = mk_easy_FunMonoBind tycon_loc succ_RDR [a_Pat] [] $
440 untag_Expr tycon [(a_RDR, ah_RDR)] $
441 HsIf (mkHsApps eq_RDR [HsVar (maxtag_RDR tycon),
442 mkHsVarApps mkInt_RDR [ah_RDR]])
443 (illegal_Expr "succ" occ_nm "tried to take `succ' of last tag in enumeration")
444 (HsApp (HsVar (tag2con_RDR tycon))
445 (mkHsApps plus_RDR [mkHsVarApps mkInt_RDR [ah_RDR],
450 = mk_easy_FunMonoBind tycon_loc pred_RDR [a_Pat] [] $
451 untag_Expr tycon [(a_RDR, ah_RDR)] $
452 HsIf (mkHsApps eq_RDR [mkHsIntLit 0,
453 mkHsVarApps mkInt_RDR [ah_RDR]])
454 (illegal_Expr "pred" occ_nm "tried to take `pred' of first tag in enumeration")
455 (HsApp (HsVar (tag2con_RDR tycon))
456 (mkHsApps plus_RDR [mkHsVarApps mkInt_RDR [ah_RDR],
457 HsLit (HsInt (-1))]))
461 = mk_easy_FunMonoBind tycon_loc toEnum_RDR [a_Pat] [] $
462 HsIf (mkHsApps and_RDR
463 [mkHsApps ge_RDR [HsVar a_RDR, mkHsIntLit 0],
464 mkHsApps le_RDR [HsVar a_RDR, HsVar (maxtag_RDR tycon)]])
465 (mkHsVarApps (tag2con_RDR tycon) [a_RDR])
466 (illegal_toEnum_tag occ_nm (maxtag_RDR tycon))
470 = mk_easy_FunMonoBind tycon_loc enumFrom_RDR [a_Pat] [] $
471 untag_Expr tycon [(a_RDR, ah_RDR)] $
473 [HsVar (tag2con_RDR tycon),
474 HsPar (enum_from_to_Expr
475 (mkHsVarApps mkInt_RDR [ah_RDR])
476 (HsVar (maxtag_RDR tycon)))]
479 = mk_easy_FunMonoBind tycon_loc enumFromThen_RDR [a_Pat, b_Pat] [] $
480 untag_Expr tycon [(a_RDR, ah_RDR), (b_RDR, bh_RDR)] $
481 HsApp (mkHsVarApps map_RDR [tag2con_RDR tycon]) $
482 HsPar (enum_from_then_to_Expr
483 (mkHsVarApps mkInt_RDR [ah_RDR])
484 (mkHsVarApps mkInt_RDR [bh_RDR])
485 (HsIf (mkHsApps gt_RDR [mkHsVarApps mkInt_RDR [ah_RDR],
486 mkHsVarApps mkInt_RDR [bh_RDR]])
488 (HsVar (maxtag_RDR tycon))
492 = mk_easy_FunMonoBind tycon_loc fromEnum_RDR [a_Pat] [] $
493 untag_Expr tycon [(a_RDR, ah_RDR)] $
494 (mkHsVarApps mkInt_RDR [ah_RDR])
497 %************************************************************************
499 \subsubsection{Generating @Bounded@ instance declarations}
501 %************************************************************************
504 gen_Bounded_binds tycon
505 = if isEnumerationTyCon tycon then
506 min_bound_enum `AndMonoBinds` max_bound_enum
508 ASSERT(isSingleton data_cons)
509 min_bound_1con `AndMonoBinds` max_bound_1con
511 data_cons = tyConDataCons tycon
512 tycon_loc = getSrcLoc tycon
514 ----- enum-flavored: ---------------------------
515 min_bound_enum = mk_easy_FunMonoBind tycon_loc minBound_RDR [] [] (HsVar data_con_1_RDR)
516 max_bound_enum = mk_easy_FunMonoBind tycon_loc maxBound_RDR [] [] (HsVar data_con_N_RDR)
518 data_con_1 = head data_cons
519 data_con_N = last data_cons
520 data_con_1_RDR = getRdrName data_con_1
521 data_con_N_RDR = getRdrName data_con_N
523 ----- single-constructor-flavored: -------------
524 arity = dataConSourceArity data_con_1
526 min_bound_1con = mk_easy_FunMonoBind tycon_loc minBound_RDR [] [] $
527 mkHsVarApps data_con_1_RDR (nOfThem arity minBound_RDR)
528 max_bound_1con = mk_easy_FunMonoBind tycon_loc maxBound_RDR [] [] $
529 mkHsVarApps data_con_1_RDR (nOfThem arity maxBound_RDR)
532 %************************************************************************
534 \subsubsection{Generating @Ix@ instance declarations}
536 %************************************************************************
538 Deriving @Ix@ is only possible for enumeration types and
539 single-constructor types. We deal with them in turn.
541 For an enumeration type, e.g.,
543 data Foo ... = N1 | N2 | ... | Nn
545 things go not too differently from @Enum@:
547 instance ... Ix (Foo ...) where
549 = map tag2con_Foo [con2tag_Foo a .. con2tag_Foo b]
553 = case (con2tag_Foo a) of { a# ->
554 case (con2tag_Foo b) of { b# ->
555 map tag2con_Foo (enumFromTo (I# a#) (I# b#))
560 then case (con2tag_Foo d -# con2tag_Foo a) of
562 else error "Ix.Foo.index: out of range"
566 p_tag = con2tag_Foo c
568 p_tag >= con2tag_Foo a && p_tag <= con2tag_Foo b
572 = case (con2tag_Foo a) of { a_tag ->
573 case (con2tag_Foo b) of { b_tag ->
574 case (con2tag_Foo c) of { c_tag ->
575 if (c_tag >=# a_tag) then
581 (modulo suitable case-ification to handle the unlifted tags)
583 For a single-constructor type (NB: this includes all tuples), e.g.,
585 data Foo ... = MkFoo a b Int Double c c
587 we follow the scheme given in Figure~19 of the Haskell~1.2 report
591 gen_Ix_binds :: TyCon -> RdrNameMonoBinds
594 = if isEnumerationTyCon tycon
598 tycon_str = getOccString tycon
599 tycon_loc = getSrcLoc tycon
601 --------------------------------------------------------------
602 enum_ixes = enum_range `AndMonoBinds`
603 enum_index `AndMonoBinds` enum_inRange
606 = mk_easy_FunMonoBind tycon_loc range_RDR
607 [TuplePat [a_Pat, b_Pat] Boxed] [] $
608 untag_Expr tycon [(a_RDR, ah_RDR)] $
609 untag_Expr tycon [(b_RDR, bh_RDR)] $
610 HsApp (mkHsVarApps map_RDR [tag2con_RDR tycon]) $
611 HsPar (enum_from_to_Expr
612 (mkHsVarApps mkInt_RDR [ah_RDR])
613 (mkHsVarApps mkInt_RDR [bh_RDR]))
616 = mk_easy_FunMonoBind tycon_loc index_RDR
617 [AsPat c_RDR (TuplePat [a_Pat, wildPat] Boxed),
619 HsIf (HsPar (mkHsVarApps inRange_RDR [c_RDR, d_RDR])) (
620 untag_Expr tycon [(a_RDR, ah_RDR)] (
621 untag_Expr tycon [(d_RDR, dh_RDR)] (
623 rhs = mkHsVarApps mkInt_RDR [c_RDR]
626 (genOpApp (HsVar dh_RDR) minusInt_RDR (HsVar ah_RDR))
627 [mkSimpleMatch [VarPat c_RDR] rhs placeHolderType tycon_loc]
631 HsApp (HsVar error_RDR) (HsLit (HsString (mkFastString ("Ix."++tycon_str++".index: out of range\n"))))
636 = mk_easy_FunMonoBind tycon_loc inRange_RDR
637 [TuplePat [a_Pat, b_Pat] Boxed, c_Pat] [] (
638 untag_Expr tycon [(a_RDR, ah_RDR)] (
639 untag_Expr tycon [(b_RDR, bh_RDR)] (
640 untag_Expr tycon [(c_RDR, ch_RDR)] (
641 HsIf (genOpApp (HsVar ch_RDR) geInt_RDR (HsVar ah_RDR)) (
642 (genOpApp (HsVar ch_RDR) leInt_RDR (HsVar bh_RDR))
647 --------------------------------------------------------------
649 = single_con_range `AndMonoBinds`
650 single_con_index `AndMonoBinds`
654 = case maybeTyConSingleCon tycon of -- just checking...
655 Nothing -> panic "get_Ix_binds"
656 Just dc -> if (any isUnLiftedType (dataConOrigArgTys dc)) then
657 error ("ERROR: Can't derive Ix for a single-constructor type with primitive argument types: "++tycon_str)
661 con_arity = dataConSourceArity data_con
662 data_con_RDR = getRdrName data_con
664 as_needed = take con_arity as_RDRs
665 bs_needed = take con_arity bs_RDRs
666 cs_needed = take con_arity cs_RDRs
668 con_pat xs = mkConPat data_con_RDR xs
669 con_expr = mkHsVarApps data_con_RDR cs_needed
671 --------------------------------------------------------------
673 = mk_easy_FunMonoBind tycon_loc range_RDR
674 [TuplePat [con_pat as_needed, con_pat bs_needed] Boxed] [] $
675 mkHsDo ListComp stmts tycon_loc
677 stmts = zipWith3Equal "single_con_range" mk_qual as_needed bs_needed cs_needed
679 [ResultStmt con_expr tycon_loc]
681 mk_qual a b c = BindStmt (VarPat c)
682 (HsApp (HsVar range_RDR)
683 (ExplicitTuple [HsVar a, HsVar b] Boxed))
688 = mk_easy_FunMonoBind tycon_loc index_RDR
689 [TuplePat [con_pat as_needed, con_pat bs_needed] Boxed,
690 con_pat cs_needed] [range_size] (
691 foldl mk_index (mkHsIntLit 0) (zip3 as_needed bs_needed cs_needed))
693 mk_index multiply_by (l, u, i)
695 (mkHsApps index_RDR [ExplicitTuple [HsVar l, HsVar u] Boxed,
699 (HsApp (HsVar rangeSize_RDR)
700 (ExplicitTuple [HsVar l, HsVar u] Boxed))
701 ) times_RDR multiply_by
705 = mk_easy_FunMonoBind tycon_loc rangeSize_RDR
706 [TuplePat [a_Pat, b_Pat] Boxed] [] (
708 (mkHsApps index_RDR [ExplicitTuple [a_Expr, b_Expr] Boxed,
710 ) plus_RDR (mkHsIntLit 1))
714 = mk_easy_FunMonoBind tycon_loc inRange_RDR
715 [TuplePat [con_pat as_needed, con_pat bs_needed] Boxed,
718 foldl1 and_Expr (zipWith3Equal "single_con_inRange" in_range as_needed bs_needed cs_needed))
720 in_range a b c = mkHsApps inRange_RDR [ExplicitTuple [HsVar a, HsVar b] Boxed,
724 %************************************************************************
726 \subsubsection{Generating @Read@ instance declarations}
728 %************************************************************************
738 instance Read T where
742 do x <- ReadP.step Read.readPrec
743 Symbol "%%" <- Lex.lex
744 y <- ReadP.step Read.readPrec
748 do Ident "T1" <- Lex.lex
750 Ident "f1" <- Lex.lex
752 x <- ReadP.reset Read.readPrec
754 return (T1 { f1 = x }))
757 do Ident "T2" <- Lex.lexP
758 x <- ReadP.step Read.readPrec
762 readListPrec = readListPrecDefault
763 readList = readListDefault
767 gen_Read_binds :: FixityEnv -> TyCon -> RdrNameMonoBinds
769 gen_Read_binds get_fixity tycon
770 = read_prec `AndMonoBinds` default_binds
772 -----------------------------------------------------------------------
774 = mk_easy_FunMonoBind loc readList_RDR [] [] (HsVar readListDefault_RDR)
776 mk_easy_FunMonoBind loc readListPrec_RDR [] [] (HsVar readListPrecDefault_RDR)
777 -----------------------------------------------------------------------
779 loc = getSrcLoc tycon
780 data_cons = tyConDataCons tycon
781 (nullary_cons, non_nullary_cons) = partition isNullaryDataCon data_cons
783 read_prec = mk_easy_FunMonoBind loc readPrec_RDR [] []
784 (HsApp (HsVar parens_RDR) read_cons)
786 read_cons = foldr1 mk_alt (read_nullary_cons ++ read_non_nullary_cons)
787 read_non_nullary_cons = map read_non_nullary_con non_nullary_cons
790 = case nullary_cons of
792 [con] -> [mkHsDo DoExpr [bindLex (ident_pat (data_con_str con)),
793 result_stmt con []] loc]
794 _ -> [HsApp (HsVar choose_RDR)
795 (ExplicitList placeHolderType (map mk_pair nullary_cons))]
797 mk_pair con = ExplicitTuple [HsLit (data_con_str con),
798 HsApp (HsVar returnM_RDR) (HsVar (getRdrName con))]
801 read_non_nullary_con data_con
802 = mkHsApps prec_RDR [mkHsIntLit prec, mkHsDo DoExpr stmts loc]
804 stmts | is_infix = infix_stmts
805 | length labels > 0 = lbl_stmts
806 | otherwise = prefix_stmts
808 prefix_stmts -- T a b c
809 = [bindLex (ident_pat (data_con_str data_con))]
810 ++ map read_arg as_needed
811 ++ [result_stmt data_con as_needed]
813 infix_stmts -- a %% b
815 bindLex (symbol_pat (data_con_str data_con)),
817 result_stmt data_con [a1,a2]]
819 lbl_stmts -- T { f1 = a, f2 = b }
820 = [bindLex (ident_pat (data_con_str data_con)),
822 ++ concat (intersperse [read_punc ","] field_stmts)
823 ++ [read_punc "}", result_stmt data_con as_needed]
825 field_stmts = zipWithEqual "lbl_stmts" read_field labels as_needed
827 con_arity = dataConSourceArity data_con
828 nullary_con = con_arity == 0
829 labels = dataConFieldLabels data_con
830 lab_fields = length labels
831 dc_nm = getName data_con
832 is_infix = isDataSymOcc (getOccName dc_nm)
833 as_needed = take con_arity as_RDRs
834 (a1:a2:_) = as_needed
835 prec = getPrec is_infix get_fixity dc_nm
837 ------------------------------------------------------------------------
839 ------------------------------------------------------------------------
840 mk_alt e1 e2 = genOpApp e1 alt_RDR e2
841 bindLex pat = BindStmt pat (HsVar lexP_RDR) loc
842 result_stmt c as = ResultStmt (HsApp (HsVar returnM_RDR) (con_app c as)) loc
843 con_app c as = mkHsVarApps (getRdrName c) as
845 punc_pat s = ConPatIn punc_RDR (PrefixCon [LitPat (mkHsString s)]) -- Punc 'c'
846 ident_pat s = ConPatIn ident_RDR (PrefixCon [LitPat s]) -- Ident "foo"
847 symbol_pat s = ConPatIn symbol_RDR (PrefixCon [LitPat s]) -- Symbol ">>"
849 data_con_str con = mkHsString (occNameUserString (getOccName con))
851 read_punc c = bindLex (punc_pat c)
852 read_arg a = BindStmt (VarPat a) (mkHsVarApps step_RDR [readPrec_RDR]) loc
854 read_field lbl a = read_lbl lbl ++
856 BindStmt (VarPat a) (mkHsVarApps reset_RDR [readPrec_RDR]) loc]
858 -- When reading field labels we might encounter
863 read_lbl lbl | is_id_start (head lbl_str)
864 = [bindLex (ident_pat lbl_lit)]
867 bindLex (symbol_pat lbl_lit),
870 lbl_str = occNameUserString (getOccName (fieldLabelName lbl))
871 lbl_lit = mkHsString lbl_str
872 is_id_start c = isAlpha c || c == '_'
876 %************************************************************************
878 \subsubsection{Generating @Show@ instance declarations}
880 %************************************************************************
886 data Tree a = Leaf a | Tree a :^: Tree a
888 instance (Show a) => Show (Tree a) where
890 showsPrec d (Leaf m) = showParen (d > app_prec) showStr
892 showStr = showString "Leaf " . showsPrec (app_prec+1) m
894 showsPrec d (u :^: v) = showParen (d > up_prec) showStr
896 showStr = showsPrec (up_prec+1) u .
898 showsPrec (up_prec+1) v
899 -- Note: right-associativity of :^: ignored
901 up_prec = 5 -- Precedence of :^:
902 app_prec = 10 -- Application has precedence one more than
903 -- the most tightly-binding operator
906 gen_Show_binds :: FixityEnv -> TyCon -> RdrNameMonoBinds
908 gen_Show_binds get_fixity tycon
909 = shows_prec `AndMonoBinds` show_list
911 tycon_loc = getSrcLoc tycon
912 -----------------------------------------------------------------------
913 show_list = mk_easy_FunMonoBind tycon_loc showList_RDR [] []
914 (HsApp (HsVar showList___RDR) (HsPar (HsApp (HsVar showsPrec_RDR) (mkHsIntLit 0))))
915 -----------------------------------------------------------------------
916 shows_prec = mk_FunMonoBind tycon_loc showsPrec_RDR (map pats_etc (tyConDataCons tycon))
919 | nullary_con = -- skip the showParen junk...
920 ASSERT(null bs_needed)
921 ([wildPat, con_pat], mk_showString_app con_str)
924 showParen_Expr (HsPar (genOpApp a_Expr ge_RDR (HsLit (HsInt con_prec_plus_one))))
925 (HsPar (nested_compose_Expr show_thingies)))
927 data_con_RDR = getRdrName data_con
928 con_arity = dataConSourceArity data_con
929 bs_needed = take con_arity bs_RDRs
930 con_pat = mkConPat data_con_RDR bs_needed
931 nullary_con = con_arity == 0
932 labels = dataConFieldLabels data_con
933 lab_fields = length labels
934 record_syntax = lab_fields > 0
936 dc_nm = getName data_con
937 dc_occ_nm = getOccName data_con
938 con_str = occNameUserString dc_occ_nm
941 | is_infix = [show_arg1, mk_showString_app (" " ++ con_str ++ " "), show_arg2]
942 | record_syntax = mk_showString_app (con_str ++ " {") :
943 show_record_args ++ [mk_showString_app "}"]
944 | otherwise = mk_showString_app (con_str ++ " ") : show_prefix_args
946 show_label l = mk_showString_app (the_name ++ " = ")
947 -- Note the spaces around the "=" sign. If we don't have them
948 -- then we get Foo { x=-1 } and the "=-" parses as a single
949 -- lexeme. Only the space after the '=' is necessary, but
950 -- it seems tidier to have them both sides.
952 occ_nm = getOccName (fieldLabelName l)
953 nm = occNameUserString occ_nm
955 is_op = isSymOcc occ_nm -- Legal, but rare.
957 | is_op = '(':nm ++ ")"
960 show_args = [ mkHsApps showsPrec_RDR [HsLit (HsInt arg_prec), HsVar b]
962 (show_arg1:show_arg2:_) = show_args
963 show_prefix_args = intersperse (HsVar showSpace_RDR) show_args
965 -- Assumption for record syntax: no of fields == no of labelled fields
966 -- (and in same order)
967 show_record_args = concat $
968 intersperse [mk_showString_app ", "] $
969 [ [show_label lbl, arg]
970 | (lbl,arg) <- zipEqual "gen_Show_binds"
974 is_infix = isDataSymOcc dc_occ_nm
975 con_prec_plus_one = 1 + getPrec is_infix get_fixity dc_nm
976 arg_prec | record_syntax = 0 -- Record fields don't need parens
977 | otherwise = con_prec_plus_one
979 mk_showString_app str = HsApp (HsVar showString_RDR) (HsLit (mkHsString str))
983 getPrec :: Bool -> FixityEnv -> Name -> Integer
984 getPrec is_infix get_fixity nm
985 | not is_infix = appPrecedence
986 | otherwise = getPrecedence get_fixity nm
988 appPrecedence :: Integer
989 appPrecedence = fromIntegral maxPrecedence + 1
990 -- One more than the precedence of the most
991 -- tightly-binding operator
993 getPrecedence :: FixityEnv -> Name -> Integer
994 getPrecedence get_fixity nm
995 = case lookupFixity get_fixity nm of
996 Fixity x _ -> fromIntegral x
998 isLRAssoc :: FixityEnv -> Name -> (Bool, Bool)
999 isLRAssoc get_fixity nm =
1000 case lookupFixity get_fixity nm of
1001 Fixity _ InfixN -> (False, False)
1002 Fixity _ InfixR -> (False, True)
1003 Fixity _ InfixL -> (True, False)
1007 %************************************************************************
1009 \subsection{Typeable}
1011 %************************************************************************
1019 instance (Typeable a, Typeable b) => Typeable (T a b) where
1020 typeOf _ = mkTypeRep (mkTyConRep "T")
1021 [typeOf (undefined::a),
1022 typeOf (undefined::b)]
1024 Notice the use of lexically scoped type variables.
1027 gen_Typeable_binds :: TyCon -> RdrNameMonoBinds
1028 gen_Typeable_binds tycon
1029 = mk_easy_FunMonoBind tycon_loc typeOf_RDR [WildPat placeHolderType] []
1030 (mkHsApps mkTypeRep_RDR [tycon_rep, arg_reps])
1032 tycon_loc = getSrcLoc tycon
1033 tyvars = tyConTyVars tycon
1034 tycon_rep = HsVar mkTyConRep_RDR `HsApp` HsLit (mkHsString (showSDoc (ppr tycon)))
1035 arg_reps = ExplicitList placeHolderType (map mk tyvars)
1036 mk tyvar = HsApp (HsVar typeOf_RDR)
1037 (ExprWithTySig (HsVar undefined_RDR)
1038 (HsTyVar (getRdrName tyvar)))
1043 %************************************************************************
1045 \subsection{Generating extra binds (@con2tag@ and @tag2con@)}
1047 %************************************************************************
1052 con2tag_Foo :: Foo ... -> Int#
1053 tag2con_Foo :: Int -> Foo ... -- easier if Int, not Int#
1054 maxtag_Foo :: Int -- ditto (NB: not unlifted)
1057 The `tags' here start at zero, hence the @fIRST_TAG@ (currently one)
1062 = GenCon2Tag | GenTag2Con | GenMaxTag
1064 gen_tag_n_con_monobind
1065 :: (RdrName, -- (proto)Name for the thing in question
1066 TyCon, -- tycon in question
1070 gen_tag_n_con_monobind (rdr_name, tycon, GenCon2Tag)
1071 | lots_of_constructors
1072 = mk_FunMonoBind loc rdr_name [([], get_tag_rhs)]
1075 = mk_FunMonoBind loc rdr_name (map mk_stuff (tyConDataCons tycon))
1078 loc = getSrcLoc tycon
1080 -- Give a signature to the bound variable, so
1081 -- that the case expression generated by getTag is
1082 -- monomorphic. In the push-enter model we get better code.
1083 get_tag_rhs = ExprWithTySig
1084 (HsLam (mk_match loc [VarPat a_RDR]
1085 (HsApp getTag_Expr a_Expr)
1087 (HsForAllTy Nothing [] con2tag_ty)
1088 -- Nothing => implicit quantification
1090 con2tag_ty = foldl HsAppTy (HsTyVar (getRdrName tycon))
1091 [HsTyVar (getRdrName tv) | tv <- tyConTyVars tycon]
1093 HsTyVar (getRdrName intPrimTyConName)
1095 lots_of_constructors = tyConFamilySize tycon > mAX_FAMILY_SIZE_FOR_VEC_RETURNS
1097 mk_stuff :: DataCon -> ([RdrNamePat], RdrNameHsExpr)
1099 = ([pat], HsLit (HsIntPrim (toInteger ((dataConTag var) - fIRST_TAG))))
1101 pat = ConPatIn var_RDR (PrefixCon (nOfThem (dataConSourceArity var) wildPat))
1102 var_RDR = getRdrName var
1104 gen_tag_n_con_monobind (rdr_name, tycon, GenTag2Con)
1105 = mk_FunMonoBind (getSrcLoc tycon) rdr_name
1106 [([mkConPat mkInt_RDR [a_RDR]],
1107 ExprWithTySig (HsApp tagToEnum_Expr a_Expr)
1108 (HsTyVar (getRdrName tycon)))]
1110 gen_tag_n_con_monobind (rdr_name, tycon, GenMaxTag)
1111 = mk_easy_FunMonoBind (getSrcLoc tycon)
1112 rdr_name [] [] (HsApp (HsVar mkInt_RDR) (HsLit (HsIntPrim max_tag)))
1114 max_tag = case (tyConDataCons tycon) of
1115 data_cons -> toInteger ((length data_cons) - fIRST_TAG)
1119 %************************************************************************
1121 \subsection{Utility bits for generating bindings}
1123 %************************************************************************
1125 @mk_easy_FunMonoBind fun pats binds expr@ generates:
1127 fun pat1 pat2 ... patN = expr where binds
1130 @mk_FunMonoBind fun [([p1a, p1b, ...], e1), ...]@ is for
1131 multi-clause definitions; it generates:
1133 fun p1a p1b ... p1N = e1
1134 fun p2a p2b ... p2N = e2
1136 fun pMa pMb ... pMN = eM
1140 mk_easy_FunMonoBind :: SrcLoc -> RdrName -> [RdrNamePat]
1141 -> [RdrNameMonoBinds] -> RdrNameHsExpr
1144 mk_easy_FunMonoBind loc fun pats binds expr
1145 = FunMonoBind fun False{-not infix-} [mk_easy_Match loc pats binds expr] loc
1147 mk_easy_Match loc pats binds expr
1148 = mk_match loc pats expr (mkMonoBind Recursive (andMonoBindList binds))
1149 -- The renamer expects everything in its input to be a
1150 -- "recursive" MonoBinds, and it is its job to sort things out
1153 mk_FunMonoBind :: SrcLoc -> RdrName
1154 -> [([RdrNamePat], RdrNameHsExpr)]
1157 mk_FunMonoBind loc fun [] = panic "TcGenDeriv:mk_FunMonoBind"
1158 mk_FunMonoBind loc fun pats_and_exprs
1159 = FunMonoBind fun False{-not infix-}
1160 [ mk_match loc p e EmptyBinds | (p,e) <-pats_and_exprs ]
1163 mk_match loc pats expr binds
1164 = Match (map paren pats) Nothing
1165 (GRHSs (unguardedRHS expr loc) binds placeHolderType)
1167 paren p@(VarPat _) = p
1168 paren other_p = ParPat other_p
1172 mkHsApps f xs = foldl HsApp (HsVar f) xs
1173 mkHsVarApps f xs = foldl HsApp (HsVar f) (map HsVar xs)
1175 mkHsIntLit n = HsLit (HsInt n)
1176 mkHsString s = HsString (mkFastString s)
1177 mkHsChar c = HsChar (ord c)
1179 mkConPat con vars = ConPatIn con (PrefixCon (map VarPat vars))
1180 mkNullaryConPat con = ConPatIn con (PrefixCon [])
1183 ToDo: Better SrcLocs.
1187 RdrNameHsExpr -- What to do for equality
1188 -> RdrNameHsExpr -> RdrNameHsExpr
1190 careful_compare_Case :: -- checks for primitive types...
1192 -> RdrNameHsExpr -- What to do for equality
1193 -> RdrNameHsExpr -> RdrNameHsExpr
1196 cmp_eq_Expr a b = HsApp (HsApp (HsVar cmp_eq_RDR) a) b
1197 -- Was: compare_gen_Case cmp_eq_RDR
1199 compare_gen_Case (HsVar eq_tag) a b | eq_tag == eqTag_RDR
1200 = HsApp (HsApp (HsVar compare_RDR) a) b -- Simple case
1201 compare_gen_Case eq a b -- General case
1202 = HsCase (HsPar (HsApp (HsApp (HsVar compare_RDR) a) b)) {-of-}
1203 [mkSimpleMatch [mkNullaryConPat ltTag_RDR] ltTag_Expr placeHolderType generatedSrcLoc,
1204 mkSimpleMatch [mkNullaryConPat eqTag_RDR] eq placeHolderType generatedSrcLoc,
1205 mkSimpleMatch [mkNullaryConPat gtTag_RDR] gtTag_Expr placeHolderType generatedSrcLoc]
1208 careful_compare_Case ty eq a b
1209 | not (isUnLiftedType ty) =
1210 compare_gen_Case eq a b
1212 -- we have to do something special for primitive things...
1213 HsIf (genOpApp a relevant_eq_op b)
1215 (HsIf (genOpApp a relevant_lt_op b) ltTag_Expr gtTag_Expr generatedSrcLoc)
1218 relevant_eq_op = assoc_ty_id eq_op_tbl ty
1219 relevant_lt_op = assoc_ty_id lt_op_tbl ty
1221 assoc_ty_id tyids ty
1222 = if null res then panic "assoc_ty"
1225 res = [id | (ty',id) <- tyids, ty `tcEqType` ty']
1228 [(charPrimTy, eqChar_RDR)
1229 ,(intPrimTy, eqInt_RDR)
1230 ,(wordPrimTy, eqWord_RDR)
1231 ,(addrPrimTy, eqAddr_RDR)
1232 ,(floatPrimTy, eqFloat_RDR)
1233 ,(doublePrimTy, eqDouble_RDR)
1237 [(charPrimTy, ltChar_RDR)
1238 ,(intPrimTy, ltInt_RDR)
1239 ,(wordPrimTy, ltWord_RDR)
1240 ,(addrPrimTy, ltAddr_RDR)
1241 ,(floatPrimTy, ltFloat_RDR)
1242 ,(doublePrimTy, ltDouble_RDR)
1245 -----------------------------------------------------------------------
1247 and_Expr, append_Expr :: RdrNameHsExpr -> RdrNameHsExpr -> RdrNameHsExpr
1249 and_Expr a b = genOpApp a and_RDR b
1250 append_Expr a b = genOpApp a append_RDR b
1252 -----------------------------------------------------------------------
1254 eq_Expr :: Type -> RdrNameHsExpr -> RdrNameHsExpr -> RdrNameHsExpr
1255 eq_Expr ty a b = genOpApp a eq_op b
1258 | not (isUnLiftedType ty) = eq_RDR
1260 -- we have to do something special for primitive things...
1261 assoc_ty_id eq_op_tbl ty
1266 untag_Expr :: TyCon -> [(RdrName, RdrName)] -> RdrNameHsExpr -> RdrNameHsExpr
1267 untag_Expr tycon [] expr = expr
1268 untag_Expr tycon ((untag_this, put_tag_here) : more) expr
1269 = HsCase (HsPar (HsApp (con2tag_Expr tycon) (HsVar untag_this))) {-of-}
1270 [mkSimpleMatch [VarPat put_tag_here] (untag_Expr tycon more expr) placeHolderType generatedSrcLoc]
1273 cmp_tags_Expr :: RdrName -- Comparison op
1274 -> RdrName -> RdrName -- Things to compare
1275 -> RdrNameHsExpr -- What to return if true
1276 -> RdrNameHsExpr -- What to return if false
1279 cmp_tags_Expr op a b true_case false_case
1280 = HsIf (genOpApp (HsVar a) op (HsVar b)) true_case false_case generatedSrcLoc
1283 :: RdrNameHsExpr -> RdrNameHsExpr
1285 enum_from_then_to_Expr
1286 :: RdrNameHsExpr -> RdrNameHsExpr -> RdrNameHsExpr
1289 enum_from_to_Expr f t2 = HsApp (HsApp (HsVar enumFromTo_RDR) f) t2
1290 enum_from_then_to_Expr f t t2 = HsApp (HsApp (HsApp (HsVar enumFromThenTo_RDR) f) t) t2
1293 :: RdrNameHsExpr -> RdrNameHsExpr
1296 showParen_Expr e1 e2 = HsApp (HsApp (HsVar showParen_RDR) e1) e2
1298 nested_compose_Expr :: [RdrNameHsExpr] -> RdrNameHsExpr
1300 nested_compose_Expr [e] = parenify e
1301 nested_compose_Expr (e:es)
1302 = HsApp (HsApp (HsVar compose_RDR) (parenify e)) (nested_compose_Expr es)
1304 -- impossible_Expr is used in case RHSs that should never happen.
1305 -- We generate these to keep the desugarer from complaining that they *might* happen!
1306 impossible_Expr = HsApp (HsVar error_RDR) (HsLit (HsString (mkFastString "Urk! in TcGenDeriv")))
1308 -- illegal_Expr is used when signalling error conditions in the RHS of a derived
1309 -- method. It is currently only used by Enum.{succ,pred}
1310 illegal_Expr meth tp msg =
1311 HsApp (HsVar error_RDR) (HsLit (HsString (mkFastString (meth ++ '{':tp ++ "}: " ++ msg))))
1313 -- illegal_toEnum_tag is an extended version of illegal_Expr, which also allows you
1314 -- to include the value of a_RDR in the error string.
1315 illegal_toEnum_tag tp maxtag =
1316 HsApp (HsVar error_RDR)
1317 (HsApp (HsApp (HsVar append_RDR)
1318 (HsLit (HsString (mkFastString ("toEnum{" ++ tp ++ "}: tag (")))))
1319 (HsApp (HsApp (HsApp
1320 (HsVar showsPrec_RDR)
1325 (HsLit (HsString (mkFastString ") is outside of enumeration's range (0,"))))
1326 (HsApp (HsApp (HsApp
1327 (HsVar showsPrec_RDR)
1330 (HsLit (HsString (mkFastString ")")))))))
1332 parenify e@(HsVar _) = e
1333 parenify e = HsPar e
1335 -- genOpApp wraps brackets round the operator application, so that the
1336 -- renamer won't subsequently try to re-associate it.
1337 -- For some reason the renamer doesn't reassociate it right, and I can't
1338 -- be bothered to find out why just now.
1340 genOpApp e1 op e2 = mkHsOpApp e1 op e2
1344 varUnqual n = mkUnqual OccName.varName n
1346 zz_a_RDR = varUnqual FSLIT("_a")
1347 a_RDR = varUnqual FSLIT("a")
1348 b_RDR = varUnqual FSLIT("b")
1349 c_RDR = varUnqual FSLIT("c")
1350 d_RDR = varUnqual FSLIT("d")
1351 ah_RDR = varUnqual FSLIT("a#")
1352 bh_RDR = varUnqual FSLIT("b#")
1353 ch_RDR = varUnqual FSLIT("c#")
1354 dh_RDR = varUnqual FSLIT("d#")
1355 cmp_eq_RDR = varUnqual FSLIT("cmp_eq")
1356 rangeSize_RDR = varUnqual FSLIT("rangeSize")
1358 as_RDRs = [ varUnqual (mkFastString ("a"++show i)) | i <- [(1::Int) .. ] ]
1359 bs_RDRs = [ varUnqual (mkFastString ("b"++show i)) | i <- [(1::Int) .. ] ]
1360 cs_RDRs = [ varUnqual (mkFastString ("c"++show i)) | i <- [(1::Int) .. ] ]
1362 zz_a_Expr = HsVar zz_a_RDR
1363 a_Expr = HsVar a_RDR
1364 b_Expr = HsVar b_RDR
1365 c_Expr = HsVar c_RDR
1366 d_Expr = HsVar d_RDR
1367 ltTag_Expr = HsVar ltTag_RDR
1368 eqTag_Expr = HsVar eqTag_RDR
1369 gtTag_Expr = HsVar gtTag_RDR
1370 false_Expr = HsVar false_RDR
1371 true_Expr = HsVar true_RDR
1373 getTag_Expr = HsVar getTag_RDR
1374 tagToEnum_Expr = HsVar tagToEnum_RDR
1375 con2tag_Expr tycon = HsVar (con2tag_RDR tycon)
1377 wildPat = WildPat placeHolderType
1378 zz_a_Pat = VarPat zz_a_RDR
1379 a_Pat = VarPat a_RDR
1380 b_Pat = VarPat b_RDR
1381 c_Pat = VarPat c_RDR
1382 d_Pat = VarPat d_RDR
1384 con2tag_RDR, tag2con_RDR, maxtag_RDR :: TyCon -> RdrName
1386 con2tag_RDR tycon = varUnqual (mkFastString ("con2tag_" ++ occNameString (getOccName tycon) ++ "#"))
1387 tag2con_RDR tycon = varUnqual (mkFastString ("tag2con_" ++ occNameString (getOccName tycon) ++ "#"))
1388 maxtag_RDR tycon = varUnqual (mkFastString ("maxtag_" ++ occNameString (getOccName tycon) ++ "#"))
1391 RdrNames for PrimOps. Can't be done in PrelNames, because PrimOp imports
1392 PrelNames, so PrelNames can't import PrimOp.
1395 minusInt_RDR = nameRdrName minusIntName
1396 eqInt_RDR = nameRdrName eqIntName
1397 ltInt_RDR = nameRdrName ltIntName
1398 geInt_RDR = nameRdrName geIntName
1399 leInt_RDR = nameRdrName leIntName
1400 eqChar_RDR = nameRdrName eqCharName
1401 eqWord_RDR = nameRdrName eqWordName
1402 eqAddr_RDR = nameRdrName eqAddrName
1403 eqFloat_RDR = nameRdrName eqFloatName
1404 eqDouble_RDR = nameRdrName eqDoubleName
1405 ltChar_RDR = nameRdrName ltCharName
1406 ltWord_RDR = nameRdrName ltWordName
1407 ltAddr_RDR = nameRdrName ltAddrName
1408 ltFloat_RDR = nameRdrName ltFloatName
1409 ltDouble_RDR = nameRdrName ltDoubleName
1410 tagToEnum_RDR = nameRdrName tagToEnumName