2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[TyCon]{The @TyCon@ datatype}
8 TyCon, ArgVrcs, FieldLabel,
13 AlgTyConRhs(..), visibleDataCons,
15 isFunTyCon, isUnLiftedTyCon, isProductTyCon,
16 isAlgTyCon, isDataTyCon, isSynTyCon, isNewTyCon, isPrimTyCon,
17 isEnumerationTyCon, isGadtSyntaxTyCon,
18 isTupleTyCon, isUnboxedTupleTyCon, isBoxedTupleTyCon, tupleTyConBoxity,
19 isRecursiveTyCon, newTyConRep, newTyConRhs, newTyConCo,
20 isHiBootTyCon, isSuperKindTyCon,
21 isCoercionTyCon_maybe, isCoercionTyCon,
23 tcExpandTyCon_maybe, coreExpandTyCon_maybe, stgExpandTyCon_maybe,
25 makeTyConAbstract, isAbstractTyCon,
27 mkForeignTyCon, isForeignTyCon,
45 algTyConRhs, tyConDataCons, tyConDataCons_maybe, tyConFamilySize,
49 isClassTyCon, tyConClass_maybe,
50 synTyConDefn, synTyConRhs,
51 tyConExtName, -- External name for foreign types
59 #include "HsVersions.h"
61 import {-# SOURCE #-} TypeRep ( Kind, Type, Coercion, PredType )
62 import {-# SOURCE #-} DataCon ( DataCon, isVanillaDataCon )
64 import Var ( TyVar, Id )
65 import Class ( Class )
66 import BasicTypes ( Arity, RecFlag(..), Boxity(..), isBoxed )
67 import Name ( Name, nameUnique, NamedThing(getName) )
68 import PrelNames ( Unique, Uniquable(..) )
69 import Maybes ( orElse )
74 %************************************************************************
76 \subsection{The data type}
78 %************************************************************************
83 tyConUnique :: Unique,
90 | AlgTyCon { -- Data type, and newtype decls.
91 -- All lifted, all boxed
92 tyConUnique :: Unique,
97 tyConTyVars :: [TyVar], -- Scopes over (a) the [PredType] in AlgTyConRhs.DataTyCon
98 -- (b) the cached types in AlgTyConRhs.NewTyCon
99 -- But not over the data constructors
102 algTcSelIds :: [Id], -- Its record selectors (empty if none):
104 algTcGadtSyntax :: Bool, -- True <=> the data type was declared using GADT syntax
105 -- That doesn't mean it's a true GADT; only that the "where"
106 -- form was used. This field is used only to guide
108 algTcStupidTheta :: [PredType], -- The "stupid theta" for the data type
109 -- (always empty for GADTs)
111 algTcRhs :: AlgTyConRhs, -- Data constructors in here
113 algTcRec :: RecFlag, -- Tells whether the data type is part of
114 -- a mutually-recursive group or not
116 hasGenerics :: Bool, -- True <=> generic to/from functions are available
117 -- (in the exports of the data type's source module)
119 algTcClass :: Maybe Class
120 -- Just cl if this tycon came from a class declaration
124 tyConUnique :: Unique,
128 tyConBoxed :: Boxity,
129 tyConTyVars :: [TyVar],
135 tyConUnique :: Unique,
140 tyConTyVars :: [TyVar], -- Bound tyvars
141 synTcRhs :: Type, -- Right-hand side, mentioning these type vars.
142 -- Acts as a template for the expansion when
143 -- the tycon is applied to some types.
147 | PrimTyCon { -- Primitive types; cannot be defined in Haskell
148 -- Now includes foreign-imported types
149 -- Also includes Kinds
150 tyConUnique :: Unique,
156 primTyConRep :: PrimRep,
157 -- Many primitive tycons are unboxed, but some are
158 -- boxed (represented by pointers). The CgRep tells.
160 isUnLifted :: Bool, -- Most primitive tycons are unlifted,
161 -- but foreign-imported ones may not be
162 tyConExtName :: Maybe FastString -- Just xx for foreign-imported types
165 | CoercionTyCon { -- E.g. (:=:), sym, trans, left, right
166 -- INVARIANT: coercions are always fully applied
167 tyConUnique :: Unique,
170 coKindFun :: [Type] -> Kind
173 | SuperKindTyCon { -- Super Kinds, TY (box) and CO (diamond).
174 -- They have no kind; and arity zero
175 tyConUnique :: Unique,
181 type SuperKindCon = TyCon
183 type FieldLabel = Name
185 type ArgVrcs = [(Bool,Bool)] -- Tyvar variance info: [(occPos,occNeg)]
186 -- [] means "no information, assume the worst"
189 = AbstractTyCon -- We know nothing about this data type, except
190 -- that it's represented by a pointer
191 -- Used when we export a data type abstractly into
195 data_cons :: [DataCon],
196 -- The constructors; can be empty if the user declares
197 -- the type to have no constructors
198 -- INVARIANT: Kept in order of increasing tag
199 -- (see the tag assignment in DataCon.mkDataCon)
200 is_enum :: Bool -- Cached: True <=> an enumeration type
201 } -- Includes data types with no constructors.
204 data_con :: DataCon, -- The unique constructor; it has no existentials
206 nt_rhs :: Type, -- Cached: the argument type of the constructor
207 -- = the representation type of the tycon
208 -- The free tyvars of this type are the tyConTyVars
210 nt_co :: TyCon, -- The coercion used to create the newtype
211 -- from the representation
212 -- See Note [Newtype coercions]
214 nt_etad_rhs :: ([TyVar], Type) ,
215 -- The same again, but this time eta-reduced
216 -- hence the [TyVar] which may be shorter than the declared
217 -- arity of the TyCon. See Note [Newtype eta]
219 nt_rep :: Type -- Cached: the *ultimate* representation type
220 -- By 'ultimate' I mean that the top-level constructor
221 -- of the rep type is not itself a newtype or type synonym.
222 -- The rep type isn't entirely simple:
223 -- for a recursive newtype we pick () as the rep type
226 -- This one does not need to be eta reduced; hence its
227 -- free type variables are conveniently tyConTyVars
229 -- newtype T a = MkT [(a,Int)]
230 -- The rep type is [(a,Int)]
231 -- NB: the rep type isn't necessarily the original RHS of the
232 -- newtype decl, because the rep type looks through other
235 visibleDataCons :: AlgTyConRhs -> [DataCon]
236 visibleDataCons AbstractTyCon = []
237 visibleDataCons (DataTyCon{ data_cons = cs }) = cs
238 visibleDataCons (NewTyCon{ data_con = c }) = [c]
241 Note [Newtype coercions]
242 ~~~~~~~~~~~~~~~~~~~~~~~~
244 The NewTyCon field nt_co is a a TyCon (a coercion constructor in fact)
245 which is used for coercing from the representation type of the
246 newtype, to the newtype itself. For example,
248 newtype T a = MkT [a]
250 the NewTyCon for T will contain nt_co = CoT where CoT t : [t] :=: T t.
251 This TyCon is a CoercionTyCon, so it does not have a kind on its own;
252 it basically has its own typing rule for the fully-applied version.
253 If the newtype T has k type variables then CoT has arity k.
258 newtype Parser m a = MkParser (Foogle m a)
259 Are these two types equal (to Core)?
262 Well, yes. But to see that easily we eta-reduce the RHS type of
263 Parser, in this case to ([], Froogle), so that even unsaturated applications
264 of Parser will work right. This eta reduction is done when the type
265 constructor is built, and cached in NewTyCon. The cached field is
266 only used in coreExpandTyCon_maybe.
268 Here's an example that I think showed up in practice
270 newtype T a = MkT [a]
271 newtype Foo m = MkFoo (forall a. m a -> Int)
277 w2 = MkFoo (\(MkT x) -> case w1 of MkFoo f -> f x)
279 After desugaring, and discading the data constructors for the newtypes,
283 And now Lint complains unless Foo T == Foo [], and that requires T==[]
286 %************************************************************************
290 %************************************************************************
292 A PrimRep is an abstraction of a type. It contains information that
293 the code generator needs in order to pass arguments, return results,
294 and store values of this type.
296 A PrimRep is somewhat similar to a CgRep (see codeGen/SMRep) and a
297 MachRep (see cmm/MachOp), although each of these types has a distinct
298 and clearly defined purpose:
300 - A PrimRep is a CgRep + information about signedness + information
301 about primitive pointers (AddrRep). Signedness and primitive
302 pointers are required when passing a primitive type to a foreign
303 function, but aren't needed for call/return conventions of Haskell
306 - A MachRep is a basic machine type (non-void, doesn't contain
307 information on pointerhood or signedness, but contains some
308 reps that don't have corresponding Haskell types).
314 | IntRep -- signed, word-sized
315 | WordRep -- unsinged, word-sized
316 | Int64Rep -- signed, 64 bit (32-bit words only)
317 | Word64Rep -- unsigned, 64 bit (32-bit words only)
318 | AddrRep -- a pointer, but not to a Haskell value
323 %************************************************************************
325 \subsection{TyCon Construction}
327 %************************************************************************
329 Note: the TyCon constructors all take a Kind as one argument, even though
330 they could, in principle, work out their Kind from their other arguments.
331 But to do so they need functions from Types, and that makes a nasty
332 module mutual-recursion. And they aren't called from many places.
333 So we compromise, and move their Kind calculation to the call site.
336 mkFunTyCon :: Name -> Kind -> TyCon
339 tyConUnique = nameUnique name,
345 -- This is the making of a TyCon. Just the same as the old mkAlgTyCon,
346 -- but now you also have to pass in the generic information about the type
347 -- constructor - you can get hold of it easily (see Generics module)
348 mkAlgTyCon name kind tyvars argvrcs stupid rhs sel_ids is_rec gen_info gadt_syn
351 tyConUnique = nameUnique name,
353 tyConArity = length tyvars,
354 tyConTyVars = tyvars,
356 algTcStupidTheta = stupid,
358 algTcSelIds = sel_ids,
359 algTcClass = Nothing,
361 algTcGadtSyntax = gadt_syn,
362 hasGenerics = gen_info
365 mkClassTyCon name kind tyvars argvrcs rhs clas is_rec
368 tyConUnique = nameUnique name,
370 tyConArity = length tyvars,
371 tyConTyVars = tyvars,
373 algTcStupidTheta = [],
376 algTcClass = Just clas,
378 algTcGadtSyntax = False, -- Doesn't really matter
383 mkTupleTyCon name kind arity tyvars con boxed gen_info
385 tyConUnique = nameUnique name,
390 tyConTyVars = tyvars,
392 hasGenerics = gen_info
395 -- Foreign-imported (.NET) type constructors are represented
396 -- as primitive, but *lifted*, TyCons for now. They are lifted
397 -- because the Haskell type T representing the (foreign) .NET
398 -- type T is actually implemented (in ILX) as a thunk<T>
399 mkForeignTyCon name ext_name kind arity arg_vrcs
402 tyConUnique = nameUnique name,
406 primTyConRep = PtrRep, -- they all do
408 tyConExtName = ext_name
412 -- most Prim tycons are lifted
413 mkPrimTyCon name kind arity arg_vrcs rep
414 = mkPrimTyCon' name kind arity arg_vrcs rep True
416 mkVoidPrimTyCon name kind arity arg_vrcs
417 = mkPrimTyCon' name kind arity arg_vrcs VoidRep True
419 -- but RealWorld is lifted
420 mkLiftedPrimTyCon name kind arity arg_vrcs rep
421 = mkPrimTyCon' name kind arity arg_vrcs rep False
423 mkPrimTyCon' name kind arity arg_vrcs rep is_unlifted
426 tyConUnique = nameUnique name,
431 isUnLifted = is_unlifted,
432 tyConExtName = Nothing
435 mkSynTyCon name kind tyvars rhs argvrcs
438 tyConUnique = nameUnique name,
440 tyConArity = length tyvars,
441 tyConTyVars = tyvars,
446 mkCoercionTyCon name arity kindRule
449 tyConUnique = nameUnique name,
454 -- Super kinds always have arity zero
455 mkSuperKindTyCon name
458 tyConUnique = nameUnique name
463 isFunTyCon :: TyCon -> Bool
464 isFunTyCon (FunTyCon {}) = True
467 isAbstractTyCon :: TyCon -> Bool
468 isAbstractTyCon (AlgTyCon { algTcRhs = AbstractTyCon }) = True
469 isAbstractTyCon _ = False
471 makeTyConAbstract :: TyCon -> TyCon
472 makeTyConAbstract tc@(AlgTyCon {}) = tc { algTcRhs = AbstractTyCon }
473 makeTyConAbstract tc = pprPanic "makeTyConAbstract" (ppr tc)
475 isPrimTyCon :: TyCon -> Bool
476 isPrimTyCon (PrimTyCon {}) = True
477 isPrimTyCon _ = False
479 isUnLiftedTyCon :: TyCon -> Bool
480 isUnLiftedTyCon (PrimTyCon {isUnLifted = is_unlifted}) = is_unlifted
481 isUnLiftedTyCon (TupleTyCon {tyConBoxed = boxity}) = not (isBoxed boxity)
482 isUnLiftedTyCon _ = False
484 -- isAlgTyCon returns True for both @data@ and @newtype@
485 isAlgTyCon :: TyCon -> Bool
486 isAlgTyCon (AlgTyCon {}) = True
487 isAlgTyCon (TupleTyCon {}) = True
488 isAlgTyCon other = False
490 isDataTyCon :: TyCon -> Bool
491 -- isDataTyCon returns True for data types that are represented by
492 -- heap-allocated constructors.
493 -- These are srcutinised by Core-level @case@ expressions, and they
494 -- get info tables allocated for them.
495 -- True for all @data@ types
496 -- False for newtypes
498 isDataTyCon tc@(AlgTyCon {algTcRhs = rhs})
502 AbstractTyCon -> pprPanic "isDataTyCon" (ppr tc)
504 isDataTyCon (TupleTyCon {tyConBoxed = boxity}) = isBoxed boxity
505 isDataTyCon other = False
507 isNewTyCon :: TyCon -> Bool
508 isNewTyCon (AlgTyCon {algTcRhs = NewTyCon {}}) = True
509 isNewTyCon other = False
511 isProductTyCon :: TyCon -> Bool
513 -- has *one* constructor,
514 -- is *not* existential
516 -- may be DataType or NewType,
517 -- may be unboxed or not,
518 -- may be recursive or not
519 isProductTyCon tc@(AlgTyCon {}) = case algTcRhs tc of
520 DataTyCon{ data_cons = [data_con] }
521 -> isVanillaDataCon data_con
524 isProductTyCon (TupleTyCon {}) = True
525 isProductTyCon other = False
527 isSynTyCon :: TyCon -> Bool
528 isSynTyCon (SynTyCon {}) = True
531 isGadtSyntaxTyCon :: TyCon -> Bool
532 isGadtSyntaxTyCon (AlgTyCon { algTcGadtSyntax = res }) = res
533 isGadtSyntaxTyCon other = False
535 isEnumerationTyCon :: TyCon -> Bool
536 isEnumerationTyCon (AlgTyCon {algTcRhs = DataTyCon { is_enum = res }}) = res
537 isEnumerationTyCon other = False
539 isTupleTyCon :: TyCon -> Bool
540 -- The unit tycon didn't used to be classed as a tuple tycon
541 -- but I thought that was silly so I've undone it
542 -- If it can't be for some reason, it should be a AlgTyCon
544 -- NB: when compiling Data.Tuple, the tycons won't reply True to
545 -- isTupleTyCon, becuase they are built as AlgTyCons. However they
546 -- get spat into the interface file as tuple tycons, so I don't think
548 isTupleTyCon (TupleTyCon {}) = True
549 isTupleTyCon other = False
551 isUnboxedTupleTyCon :: TyCon -> Bool
552 isUnboxedTupleTyCon (TupleTyCon {tyConBoxed = boxity}) = not (isBoxed boxity)
553 isUnboxedTupleTyCon other = False
555 isBoxedTupleTyCon :: TyCon -> Bool
556 isBoxedTupleTyCon (TupleTyCon {tyConBoxed = boxity}) = isBoxed boxity
557 isBoxedTupleTyCon other = False
559 tupleTyConBoxity tc = tyConBoxed tc
561 isRecursiveTyCon :: TyCon -> Bool
562 isRecursiveTyCon (AlgTyCon {algTcRec = Recursive}) = True
563 isRecursiveTyCon other = False
565 isHiBootTyCon :: TyCon -> Bool
566 -- Used for knot-tying in hi-boot files
567 isHiBootTyCon (AlgTyCon {algTcRhs = AbstractTyCon}) = True
568 isHiBootTyCon other = False
570 isForeignTyCon :: TyCon -> Bool
571 -- isForeignTyCon identifies foreign-imported type constructors
572 isForeignTyCon (PrimTyCon {tyConExtName = Just _}) = True
573 isForeignTyCon other = False
575 isSuperKindTyCon :: TyCon -> Bool
576 isSuperKindTyCon (SuperKindTyCon {}) = True
577 isSuperKindTyCon other = False
579 isCoercionTyCon_maybe :: TyCon -> Maybe (Arity, [Type] -> Kind)
580 isCoercionTyCon_maybe (CoercionTyCon {tyConArity = ar, coKindFun = rule})
582 isCoercionTyCon_maybe other = Nothing
584 isCoercionTyCon (CoercionTyCon {}) = True
585 isCoercionTyCon other = False
589 -----------------------------------------------
590 -- Expand type-constructor applications
591 -----------------------------------------------
594 tcExpandTyCon_maybe, coreExpandTyCon_maybe
596 -> [Type] -- Args to tycon
597 -> Maybe ([(TyVar,Type)], -- Substitution
598 Type, -- Body type (not yet substituted)
599 [Type]) -- Leftover args
601 -- For the *typechecker* view, we expand synonyms only
602 tcExpandTyCon_maybe (SynTyCon {tyConTyVars = tvs, synTcRhs = rhs }) tys
604 tcExpandTyCon_maybe other_tycon tys = Nothing
607 -- For the *Core* view, we expand synonyms only as well
609 coreExpandTyCon_maybe (AlgTyCon {algTcRec = NonRecursive, -- Not recursive
610 algTcRhs = NewTyCon { nt_etad_rhs = etad_rhs }}) tys
611 = case etad_rhs of -- Don't do this in the pattern match, lest we accidentally
612 -- match the etad_rhs of a *recursive* newtype
613 (tvs,rhs) -> expand tvs rhs tys
615 coreExpandTyCon_maybe tycon tys = tcExpandTyCon_maybe tycon tys
618 -- For the *STG* view, we expand synonyms *and* non-recursive newtypes
619 stgExpandTyCon_maybe (AlgTyCon {algTcRec = NonRecursive, -- Not recursive
620 algTcRhs = NewTyCon { nt_etad_rhs = etad_rhs }}) tys
621 = case etad_rhs of -- Don't do this in the pattern match, lest we accidentally
622 -- match the etad_rhs of a *recursive* newtype
623 (tvs,rhs) -> expand tvs rhs tys
625 stgExpandTyCon_maybe tycon tys = coreExpandTyCon_maybe tycon tys
628 expand :: [TyVar] -> Type -- Template
630 -> Maybe ([(TyVar,Type)], Type, [Type]) -- Expansion
632 = case n_tvs `compare` length tys of
633 LT -> Just (tvs `zip` tys, rhs, drop n_tvs tys)
634 EQ -> Just (tvs `zip` tys, rhs, [])
641 tyConHasGenerics :: TyCon -> Bool
642 tyConHasGenerics (AlgTyCon {hasGenerics = hg}) = hg
643 tyConHasGenerics (TupleTyCon {hasGenerics = hg}) = hg
644 tyConHasGenerics other = False -- Synonyms
646 tyConDataCons :: TyCon -> [DataCon]
647 -- It's convenient for tyConDataCons to return the
648 -- empty list for type synonyms etc
649 tyConDataCons tycon = tyConDataCons_maybe tycon `orElse` []
651 tyConDataCons_maybe :: TyCon -> Maybe [DataCon]
652 tyConDataCons_maybe (AlgTyCon {algTcRhs = DataTyCon { data_cons = cons }}) = Just cons
653 tyConDataCons_maybe (AlgTyCon {algTcRhs = NewTyCon { data_con = con }}) = Just [con]
654 tyConDataCons_maybe (TupleTyCon {dataCon = con}) = Just [con]
655 tyConDataCons_maybe other = Nothing
657 tyConFamilySize :: TyCon -> Int
658 tyConFamilySize (AlgTyCon {algTcRhs = DataTyCon { data_cons = cons }}) = length cons
659 tyConFamilySize (AlgTyCon {algTcRhs = NewTyCon {}}) = 1
660 tyConFamilySize (TupleTyCon {}) = 1
662 tyConFamilySize other = pprPanic "tyConFamilySize:" (ppr other)
665 tyConSelIds :: TyCon -> [Id]
666 tyConSelIds (AlgTyCon {algTcSelIds = fs}) = fs
667 tyConSelIds other_tycon = []
669 algTyConRhs :: TyCon -> AlgTyConRhs
670 algTyConRhs (AlgTyCon {algTcRhs = rhs}) = rhs
671 algTyConRhs (TupleTyCon {dataCon = con}) = DataTyCon { data_cons = [con], is_enum = False }
672 algTyConRhs other = pprPanic "algTyConRhs" (ppr other)
676 newTyConRhs :: TyCon -> ([TyVar], Type)
677 newTyConRhs (AlgTyCon {tyConTyVars = tvs, algTcRhs = NewTyCon { nt_rhs = rhs }}) = (tvs, rhs)
678 newTyConRhs tycon = pprPanic "newTyConRhs" (ppr tycon)
680 newTyConRep :: TyCon -> ([TyVar], Type)
681 newTyConRep (AlgTyCon {tyConTyVars = tvs, algTcRhs = NewTyCon { nt_rep = rep }}) = (tvs, rep)
682 newTyConRep tycon = pprPanic "newTyConRep" (ppr tycon)
684 newTyConCo :: TyCon -> TyCon
685 newTyConCo (AlgTyCon {tyConTyVars = tvs, algTcRhs = NewTyCon { nt_co = co }}) = co
686 newTyConCo tycon = pprPanic "newTyConCo" (ppr tycon)
688 tyConPrimRep :: TyCon -> PrimRep
689 tyConPrimRep (PrimTyCon {primTyConRep = rep}) = rep
690 tyConPrimRep tc = ASSERT(not (isUnboxedTupleTyCon tc)) PtrRep
694 tyConStupidTheta :: TyCon -> [PredType]
695 tyConStupidTheta (AlgTyCon {algTcStupidTheta = stupid}) = stupid
696 tyConStupidTheta (TupleTyCon {}) = []
697 tyConStupidTheta tycon = pprPanic "tyConStupidTheta" (ppr tycon)
700 @tyConArgVrcs_maybe@ gives a list of (occPos,occNeg) flags, one for
701 each tyvar, if available. See @calcAlgTyConArgVrcs@ for how this is
702 actually computed (in another file).
705 tyConArgVrcs :: TyCon -> ArgVrcs
706 tyConArgVrcs (FunTyCon {}) = [(False,True),(True,False)]
707 tyConArgVrcs (AlgTyCon {argVrcs = oi}) = oi
708 tyConArgVrcs (PrimTyCon {argVrcs = oi}) = oi
709 tyConArgVrcs (TupleTyCon {tyConArity = arity}) = (replicate arity (True,False))
710 tyConArgVrcs (SynTyCon {argVrcs = oi}) = oi
714 synTyConDefn :: TyCon -> ([TyVar], Type)
715 synTyConDefn (SynTyCon {tyConTyVars = tyvars, synTcRhs = ty}) = (tyvars,ty)
716 synTyConDefn tycon = pprPanic "getSynTyConDefn" (ppr tycon)
718 synTyConRhs :: TyCon -> Type
719 synTyConRhs tc = synTcRhs tc
723 maybeTyConSingleCon :: TyCon -> Maybe DataCon
724 maybeTyConSingleCon (AlgTyCon {algTcRhs = DataTyCon {data_cons = [c] }}) = Just c
725 maybeTyConSingleCon (AlgTyCon {algTcRhs = NewTyCon { data_con = c }}) = Just c
726 maybeTyConSingleCon (AlgTyCon {}) = Nothing
727 maybeTyConSingleCon (TupleTyCon {dataCon = con}) = Just con
728 maybeTyConSingleCon (PrimTyCon {}) = Nothing
729 maybeTyConSingleCon (FunTyCon {}) = Nothing -- case at funty
730 maybeTyConSingleCon tc = pprPanic "maybeTyConSingleCon: unexpected tycon " $ ppr tc
734 isClassTyCon :: TyCon -> Bool
735 isClassTyCon (AlgTyCon {algTcClass = Just _}) = True
736 isClassTyCon other_tycon = False
738 tyConClass_maybe :: TyCon -> Maybe Class
739 tyConClass_maybe (AlgTyCon {algTcClass = maybe_clas}) = maybe_clas
740 tyConClass_maybe ther_tycon = Nothing
744 %************************************************************************
746 \subsection[TyCon-instances]{Instance declarations for @TyCon@}
748 %************************************************************************
750 @TyCon@s are compared by comparing their @Unique@s.
752 The strictness analyser needs @Ord@. It is a lexicographic order with
753 the property @(a<=b) || (b<=a)@.
756 instance Eq TyCon where
757 a == b = case (a `compare` b) of { EQ -> True; _ -> False }
758 a /= b = case (a `compare` b) of { EQ -> False; _ -> True }
760 instance Ord TyCon where
761 a <= b = case (a `compare` b) of { LT -> True; EQ -> True; GT -> False }
762 a < b = case (a `compare` b) of { LT -> True; EQ -> False; GT -> False }
763 a >= b = case (a `compare` b) of { LT -> False; EQ -> True; GT -> True }
764 a > b = case (a `compare` b) of { LT -> False; EQ -> False; GT -> True }
765 compare a b = getUnique a `compare` getUnique b
767 instance Uniquable TyCon where
768 getUnique tc = tyConUnique tc
770 instance Outputable TyCon where
771 ppr tc = ppr (getName tc)
773 instance NamedThing TyCon where