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.
255 In the paper we'd write
256 axiom CoT : (forall t. [t]) :=: (forall t. T t)
257 and then when we used CoT at a particular type, s, we'd say
259 which encodes as (TyConApp instCoercionTyCon [TyConApp CoT [], s])
261 But in GHC we instead make CoT into a new piece of type syntax
262 (like instCoercionTyCon, symCoercionTyCon etc), which must always
263 be saturated, but which encodes as
265 In the vocabulary of the paper it's as if we had axiom declarations
267 axiom CoT t : ([t] :=: T t)
272 newtype Parser m a = MkParser (Foogle m a)
273 Are these two types equal (to Core)?
276 Well, yes. But to see that easily we eta-reduce the RHS type of
277 Parser, in this case to ([], Froogle), so that even unsaturated applications
278 of Parser will work right. This eta reduction is done when the type
279 constructor is built, and cached in NewTyCon. The cached field is
280 only used in coreExpandTyCon_maybe.
282 Here's an example that I think showed up in practice
284 newtype T a = MkT [a]
285 newtype Foo m = MkFoo (forall a. m a -> Int)
291 w2 = MkFoo (\(MkT x) -> case w1 of MkFoo f -> f x)
293 After desugaring, and discading the data constructors for the newtypes,
297 And now Lint complains unless Foo T == Foo [], and that requires T==[]
300 %************************************************************************
304 %************************************************************************
306 A PrimRep is an abstraction of a type. It contains information that
307 the code generator needs in order to pass arguments, return results,
308 and store values of this type.
310 A PrimRep is somewhat similar to a CgRep (see codeGen/SMRep) and a
311 MachRep (see cmm/MachOp), although each of these types has a distinct
312 and clearly defined purpose:
314 - A PrimRep is a CgRep + information about signedness + information
315 about primitive pointers (AddrRep). Signedness and primitive
316 pointers are required when passing a primitive type to a foreign
317 function, but aren't needed for call/return conventions of Haskell
320 - A MachRep is a basic machine type (non-void, doesn't contain
321 information on pointerhood or signedness, but contains some
322 reps that don't have corresponding Haskell types).
328 | IntRep -- signed, word-sized
329 | WordRep -- unsinged, word-sized
330 | Int64Rep -- signed, 64 bit (32-bit words only)
331 | Word64Rep -- unsigned, 64 bit (32-bit words only)
332 | AddrRep -- a pointer, but not to a Haskell value
337 %************************************************************************
339 \subsection{TyCon Construction}
341 %************************************************************************
343 Note: the TyCon constructors all take a Kind as one argument, even though
344 they could, in principle, work out their Kind from their other arguments.
345 But to do so they need functions from Types, and that makes a nasty
346 module mutual-recursion. And they aren't called from many places.
347 So we compromise, and move their Kind calculation to the call site.
350 mkFunTyCon :: Name -> Kind -> TyCon
353 tyConUnique = nameUnique name,
359 -- This is the making of a TyCon. Just the same as the old mkAlgTyCon,
360 -- but now you also have to pass in the generic information about the type
361 -- constructor - you can get hold of it easily (see Generics module)
362 mkAlgTyCon name kind tyvars argvrcs stupid rhs sel_ids is_rec gen_info gadt_syn
365 tyConUnique = nameUnique name,
367 tyConArity = length tyvars,
368 tyConTyVars = tyvars,
370 algTcStupidTheta = stupid,
372 algTcSelIds = sel_ids,
373 algTcClass = Nothing,
375 algTcGadtSyntax = gadt_syn,
376 hasGenerics = gen_info
379 mkClassTyCon name kind tyvars argvrcs rhs clas is_rec
382 tyConUnique = nameUnique name,
384 tyConArity = length tyvars,
385 tyConTyVars = tyvars,
387 algTcStupidTheta = [],
390 algTcClass = Just clas,
392 algTcGadtSyntax = False, -- Doesn't really matter
397 mkTupleTyCon name kind arity tyvars con boxed gen_info
399 tyConUnique = nameUnique name,
404 tyConTyVars = tyvars,
406 hasGenerics = gen_info
409 -- Foreign-imported (.NET) type constructors are represented
410 -- as primitive, but *lifted*, TyCons for now. They are lifted
411 -- because the Haskell type T representing the (foreign) .NET
412 -- type T is actually implemented (in ILX) as a thunk<T>
413 mkForeignTyCon name ext_name kind arity arg_vrcs
416 tyConUnique = nameUnique name,
420 primTyConRep = PtrRep, -- they all do
422 tyConExtName = ext_name
426 -- most Prim tycons are lifted
427 mkPrimTyCon name kind arity arg_vrcs rep
428 = mkPrimTyCon' name kind arity arg_vrcs rep True
430 mkVoidPrimTyCon name kind arity arg_vrcs
431 = mkPrimTyCon' name kind arity arg_vrcs VoidRep True
433 -- but RealWorld is lifted
434 mkLiftedPrimTyCon name kind arity arg_vrcs rep
435 = mkPrimTyCon' name kind arity arg_vrcs rep False
437 mkPrimTyCon' name kind arity arg_vrcs rep is_unlifted
440 tyConUnique = nameUnique name,
445 isUnLifted = is_unlifted,
446 tyConExtName = Nothing
449 mkSynTyCon name kind tyvars rhs argvrcs
452 tyConUnique = nameUnique name,
454 tyConArity = length tyvars,
455 tyConTyVars = tyvars,
460 mkCoercionTyCon name arity kindRule
463 tyConUnique = nameUnique name,
468 -- Super kinds always have arity zero
469 mkSuperKindTyCon name
472 tyConUnique = nameUnique name
477 isFunTyCon :: TyCon -> Bool
478 isFunTyCon (FunTyCon {}) = True
481 isAbstractTyCon :: TyCon -> Bool
482 isAbstractTyCon (AlgTyCon { algTcRhs = AbstractTyCon }) = True
483 isAbstractTyCon _ = False
485 makeTyConAbstract :: TyCon -> TyCon
486 makeTyConAbstract tc@(AlgTyCon {}) = tc { algTcRhs = AbstractTyCon }
487 makeTyConAbstract tc = pprPanic "makeTyConAbstract" (ppr tc)
489 isPrimTyCon :: TyCon -> Bool
490 isPrimTyCon (PrimTyCon {}) = True
491 isPrimTyCon _ = False
493 isUnLiftedTyCon :: TyCon -> Bool
494 isUnLiftedTyCon (PrimTyCon {isUnLifted = is_unlifted}) = is_unlifted
495 isUnLiftedTyCon (TupleTyCon {tyConBoxed = boxity}) = not (isBoxed boxity)
496 isUnLiftedTyCon _ = False
498 -- isAlgTyCon returns True for both @data@ and @newtype@
499 isAlgTyCon :: TyCon -> Bool
500 isAlgTyCon (AlgTyCon {}) = True
501 isAlgTyCon (TupleTyCon {}) = True
502 isAlgTyCon other = False
504 isDataTyCon :: TyCon -> Bool
505 -- isDataTyCon returns True for data types that are represented by
506 -- heap-allocated constructors.
507 -- These are srcutinised by Core-level @case@ expressions, and they
508 -- get info tables allocated for them.
509 -- True for all @data@ types
510 -- False for newtypes
512 isDataTyCon tc@(AlgTyCon {algTcRhs = rhs})
516 AbstractTyCon -> pprPanic "isDataTyCon" (ppr tc)
518 isDataTyCon (TupleTyCon {tyConBoxed = boxity}) = isBoxed boxity
519 isDataTyCon other = False
521 isNewTyCon :: TyCon -> Bool
522 isNewTyCon (AlgTyCon {algTcRhs = NewTyCon {}}) = True
523 isNewTyCon other = False
525 isProductTyCon :: TyCon -> Bool
527 -- has *one* constructor,
528 -- is *not* existential
530 -- may be DataType or NewType,
531 -- may be unboxed or not,
532 -- may be recursive or not
533 isProductTyCon tc@(AlgTyCon {}) = case algTcRhs tc of
534 DataTyCon{ data_cons = [data_con] }
535 -> isVanillaDataCon data_con
538 isProductTyCon (TupleTyCon {}) = True
539 isProductTyCon other = False
541 isSynTyCon :: TyCon -> Bool
542 isSynTyCon (SynTyCon {}) = True
545 isGadtSyntaxTyCon :: TyCon -> Bool
546 isGadtSyntaxTyCon (AlgTyCon { algTcGadtSyntax = res }) = res
547 isGadtSyntaxTyCon other = False
549 isEnumerationTyCon :: TyCon -> Bool
550 isEnumerationTyCon (AlgTyCon {algTcRhs = DataTyCon { is_enum = res }}) = res
551 isEnumerationTyCon other = False
553 isTupleTyCon :: TyCon -> Bool
554 -- The unit tycon didn't used to be classed as a tuple tycon
555 -- but I thought that was silly so I've undone it
556 -- If it can't be for some reason, it should be a AlgTyCon
558 -- NB: when compiling Data.Tuple, the tycons won't reply True to
559 -- isTupleTyCon, becuase they are built as AlgTyCons. However they
560 -- get spat into the interface file as tuple tycons, so I don't think
562 isTupleTyCon (TupleTyCon {}) = True
563 isTupleTyCon other = False
565 isUnboxedTupleTyCon :: TyCon -> Bool
566 isUnboxedTupleTyCon (TupleTyCon {tyConBoxed = boxity}) = not (isBoxed boxity)
567 isUnboxedTupleTyCon other = False
569 isBoxedTupleTyCon :: TyCon -> Bool
570 isBoxedTupleTyCon (TupleTyCon {tyConBoxed = boxity}) = isBoxed boxity
571 isBoxedTupleTyCon other = False
573 tupleTyConBoxity tc = tyConBoxed tc
575 isRecursiveTyCon :: TyCon -> Bool
576 isRecursiveTyCon (AlgTyCon {algTcRec = Recursive}) = True
577 isRecursiveTyCon other = False
579 isHiBootTyCon :: TyCon -> Bool
580 -- Used for knot-tying in hi-boot files
581 isHiBootTyCon (AlgTyCon {algTcRhs = AbstractTyCon}) = True
582 isHiBootTyCon other = False
584 isForeignTyCon :: TyCon -> Bool
585 -- isForeignTyCon identifies foreign-imported type constructors
586 isForeignTyCon (PrimTyCon {tyConExtName = Just _}) = True
587 isForeignTyCon other = False
589 isSuperKindTyCon :: TyCon -> Bool
590 isSuperKindTyCon (SuperKindTyCon {}) = True
591 isSuperKindTyCon other = False
593 isCoercionTyCon_maybe :: TyCon -> Maybe (Arity, [Type] -> Kind)
594 isCoercionTyCon_maybe (CoercionTyCon {tyConArity = ar, coKindFun = rule})
596 isCoercionTyCon_maybe other = Nothing
598 isCoercionTyCon (CoercionTyCon {}) = True
599 isCoercionTyCon other = False
603 -----------------------------------------------
604 -- Expand type-constructor applications
605 -----------------------------------------------
608 tcExpandTyCon_maybe, coreExpandTyCon_maybe
610 -> [Type] -- Args to tycon
611 -> Maybe ([(TyVar,Type)], -- Substitution
612 Type, -- Body type (not yet substituted)
613 [Type]) -- Leftover args
615 -- For the *typechecker* view, we expand synonyms only
616 tcExpandTyCon_maybe (SynTyCon {tyConTyVars = tvs, synTcRhs = rhs }) tys
618 tcExpandTyCon_maybe other_tycon tys = Nothing
621 -- For the *Core* view, we expand synonyms only as well
623 coreExpandTyCon_maybe (AlgTyCon {algTcRec = NonRecursive, -- Not recursive
624 algTcRhs = NewTyCon { nt_etad_rhs = etad_rhs }}) tys
625 = case etad_rhs of -- Don't do this in the pattern match, lest we accidentally
626 -- match the etad_rhs of a *recursive* newtype
627 (tvs,rhs) -> expand tvs rhs tys
629 coreExpandTyCon_maybe tycon tys = tcExpandTyCon_maybe tycon tys
632 -- For the *STG* view, we expand synonyms *and* non-recursive newtypes
633 stgExpandTyCon_maybe (AlgTyCon {algTcRec = NonRecursive, -- Not recursive
634 algTcRhs = NewTyCon { nt_etad_rhs = etad_rhs }}) tys
635 = case etad_rhs of -- Don't do this in the pattern match, lest we accidentally
636 -- match the etad_rhs of a *recursive* newtype
637 (tvs,rhs) -> expand tvs rhs tys
639 stgExpandTyCon_maybe tycon tys = coreExpandTyCon_maybe tycon tys
642 expand :: [TyVar] -> Type -- Template
644 -> Maybe ([(TyVar,Type)], Type, [Type]) -- Expansion
646 = case n_tvs `compare` length tys of
647 LT -> Just (tvs `zip` tys, rhs, drop n_tvs tys)
648 EQ -> Just (tvs `zip` tys, rhs, [])
655 tyConHasGenerics :: TyCon -> Bool
656 tyConHasGenerics (AlgTyCon {hasGenerics = hg}) = hg
657 tyConHasGenerics (TupleTyCon {hasGenerics = hg}) = hg
658 tyConHasGenerics other = False -- Synonyms
660 tyConDataCons :: TyCon -> [DataCon]
661 -- It's convenient for tyConDataCons to return the
662 -- empty list for type synonyms etc
663 tyConDataCons tycon = tyConDataCons_maybe tycon `orElse` []
665 tyConDataCons_maybe :: TyCon -> Maybe [DataCon]
666 tyConDataCons_maybe (AlgTyCon {algTcRhs = DataTyCon { data_cons = cons }}) = Just cons
667 tyConDataCons_maybe (AlgTyCon {algTcRhs = NewTyCon { data_con = con }}) = Just [con]
668 tyConDataCons_maybe (TupleTyCon {dataCon = con}) = Just [con]
669 tyConDataCons_maybe other = Nothing
671 tyConFamilySize :: TyCon -> Int
672 tyConFamilySize (AlgTyCon {algTcRhs = DataTyCon { data_cons = cons }}) = length cons
673 tyConFamilySize (AlgTyCon {algTcRhs = NewTyCon {}}) = 1
674 tyConFamilySize (TupleTyCon {}) = 1
676 tyConFamilySize other = pprPanic "tyConFamilySize:" (ppr other)
679 tyConSelIds :: TyCon -> [Id]
680 tyConSelIds (AlgTyCon {algTcSelIds = fs}) = fs
681 tyConSelIds other_tycon = []
683 algTyConRhs :: TyCon -> AlgTyConRhs
684 algTyConRhs (AlgTyCon {algTcRhs = rhs}) = rhs
685 algTyConRhs (TupleTyCon {dataCon = con}) = DataTyCon { data_cons = [con], is_enum = False }
686 algTyConRhs other = pprPanic "algTyConRhs" (ppr other)
690 newTyConRhs :: TyCon -> ([TyVar], Type)
691 newTyConRhs (AlgTyCon {tyConTyVars = tvs, algTcRhs = NewTyCon { nt_rhs = rhs }}) = (tvs, rhs)
692 newTyConRhs tycon = pprPanic "newTyConRhs" (ppr tycon)
694 newTyConRep :: TyCon -> ([TyVar], Type)
695 newTyConRep (AlgTyCon {tyConTyVars = tvs, algTcRhs = NewTyCon { nt_rep = rep }}) = (tvs, rep)
696 newTyConRep tycon = pprPanic "newTyConRep" (ppr tycon)
698 newTyConCo :: TyCon -> TyCon
699 newTyConCo (AlgTyCon {tyConTyVars = tvs, algTcRhs = NewTyCon { nt_co = co }}) = co
700 newTyConCo tycon = pprPanic "newTyConCo" (ppr tycon)
702 tyConPrimRep :: TyCon -> PrimRep
703 tyConPrimRep (PrimTyCon {primTyConRep = rep}) = rep
704 tyConPrimRep tc = ASSERT(not (isUnboxedTupleTyCon tc)) PtrRep
708 tyConStupidTheta :: TyCon -> [PredType]
709 tyConStupidTheta (AlgTyCon {algTcStupidTheta = stupid}) = stupid
710 tyConStupidTheta (TupleTyCon {}) = []
711 tyConStupidTheta tycon = pprPanic "tyConStupidTheta" (ppr tycon)
714 @tyConArgVrcs_maybe@ gives a list of (occPos,occNeg) flags, one for
715 each tyvar, if available. See @calcAlgTyConArgVrcs@ for how this is
716 actually computed (in another file).
719 tyConArgVrcs :: TyCon -> ArgVrcs
720 tyConArgVrcs (FunTyCon {}) = [(False,True),(True,False)]
721 tyConArgVrcs (AlgTyCon {argVrcs = oi}) = oi
722 tyConArgVrcs (PrimTyCon {argVrcs = oi}) = oi
723 tyConArgVrcs (TupleTyCon {tyConArity = arity}) = (replicate arity (True,False))
724 tyConArgVrcs (SynTyCon {argVrcs = oi}) = oi
728 synTyConDefn :: TyCon -> ([TyVar], Type)
729 synTyConDefn (SynTyCon {tyConTyVars = tyvars, synTcRhs = ty}) = (tyvars,ty)
730 synTyConDefn tycon = pprPanic "getSynTyConDefn" (ppr tycon)
732 synTyConRhs :: TyCon -> Type
733 synTyConRhs tc = synTcRhs tc
737 maybeTyConSingleCon :: TyCon -> Maybe DataCon
738 maybeTyConSingleCon (AlgTyCon {algTcRhs = DataTyCon {data_cons = [c] }}) = Just c
739 maybeTyConSingleCon (AlgTyCon {algTcRhs = NewTyCon { data_con = c }}) = Just c
740 maybeTyConSingleCon (AlgTyCon {}) = Nothing
741 maybeTyConSingleCon (TupleTyCon {dataCon = con}) = Just con
742 maybeTyConSingleCon (PrimTyCon {}) = Nothing
743 maybeTyConSingleCon (FunTyCon {}) = Nothing -- case at funty
744 maybeTyConSingleCon tc = pprPanic "maybeTyConSingleCon: unexpected tycon " $ ppr tc
748 isClassTyCon :: TyCon -> Bool
749 isClassTyCon (AlgTyCon {algTcClass = Just _}) = True
750 isClassTyCon other_tycon = False
752 tyConClass_maybe :: TyCon -> Maybe Class
753 tyConClass_maybe (AlgTyCon {algTcClass = maybe_clas}) = maybe_clas
754 tyConClass_maybe ther_tycon = Nothing
758 %************************************************************************
760 \subsection[TyCon-instances]{Instance declarations for @TyCon@}
762 %************************************************************************
764 @TyCon@s are compared by comparing their @Unique@s.
766 The strictness analyser needs @Ord@. It is a lexicographic order with
767 the property @(a<=b) || (b<=a)@.
770 instance Eq TyCon where
771 a == b = case (a `compare` b) of { EQ -> True; _ -> False }
772 a /= b = case (a `compare` b) of { EQ -> False; _ -> True }
774 instance Ord TyCon where
775 a <= b = case (a `compare` b) of { LT -> True; EQ -> True; GT -> False }
776 a < b = case (a `compare` b) of { LT -> True; EQ -> False; GT -> False }
777 a >= b = case (a `compare` b) of { LT -> False; EQ -> True; GT -> True }
778 a > b = case (a `compare` b) of { LT -> False; EQ -> False; GT -> True }
779 compare a b = getUnique a `compare` getUnique b
781 instance Uniquable TyCon where
782 getUnique tc = tyConUnique tc
784 instance Outputable TyCon where
785 ppr tc = ppr (getName tc)
787 instance NamedThing TyCon where