Make the treatment of equalities more uniform
[ghc-hetmet.git] / compiler / types / TypeRep.lhs
1 %
2 % (c) The University of Glasgow 2006
3 % (c) The GRASP/AQUA Project, Glasgow University, 1998
4 %
5 \section[TypeRep]{Type - friends' interface}
6
7 \begin{code}
8 {-# OPTIONS -w #-}
9 -- The above warning supression flag is a temporary kludge.
10 -- While working on this module you are encouraged to remove it and fix
11 -- any warnings in the module. See
12 --     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
13 -- for details
14
15 module TypeRep (
16         TyThing(..), 
17         Type(..), TyNote(..),           -- Representation visible 
18         PredType(..),                   -- to friends
19         
20         Kind, ThetaType,                -- Synonyms
21
22         funTyCon,
23
24         -- Pretty-printing
25         pprType, pprParendType, pprTypeApp,
26         pprTyThing, pprTyThingCategory, 
27         pprPred, pprTheta, pprForAll, pprThetaArrow, pprClassPred,
28
29         -- Kinds
30         liftedTypeKind, unliftedTypeKind, openTypeKind,
31         argTypeKind, ubxTupleKind,
32         isLiftedTypeKindCon, isLiftedTypeKind,
33         mkArrowKind, mkArrowKinds, isCoercionKind,
34         coVarPred,
35
36         -- Kind constructors...
37         liftedTypeKindTyCon, openTypeKindTyCon, unliftedTypeKindTyCon,
38         argTypeKindTyCon, ubxTupleKindTyCon,
39
40         -- And their names
41         unliftedTypeKindTyConName, openTypeKindTyConName,
42         ubxTupleKindTyConName, argTypeKindTyConName,
43         liftedTypeKindTyConName,
44
45         -- Super Kinds
46         tySuperKind, coSuperKind,
47         isTySuperKind, isCoSuperKind,
48         tySuperKindTyCon, coSuperKindTyCon,
49         
50         pprKind, pprParendKind
51     ) where
52
53 #include "HsVersions.h"
54
55 import {-# SOURCE #-} DataCon( DataCon, dataConName )
56
57 -- friends:
58 import Var
59 import VarSet
60 import Name
61 import OccName
62 import BasicTypes
63 import TyCon
64 import Class
65
66 -- others
67 import PrelNames
68 import Outputable
69 \end{code}
70
71 %************************************************************************
72 %*                                                                      *
73 \subsection{Type Classifications}
74 %*                                                                      *
75 %************************************************************************
76
77 A type is
78
79         *unboxed*       iff its representation is other than a pointer
80                         Unboxed types are also unlifted.
81
82         *lifted*        A type is lifted iff it has bottom as an element.
83                         Closures always have lifted types:  i.e. any
84                         let-bound identifier in Core must have a lifted
85                         type.  Operationally, a lifted object is one that
86                         can be entered.
87
88                         Only lifted types may be unified with a type variable.
89
90         *algebraic*     A type with one or more constructors, whether declared
91                         with "data" or "newtype".   
92                         An algebraic type is one that can be deconstructed
93                         with a case expression.  
94                         *NOT* the same as lifted types,  because we also 
95                         include unboxed tuples in this classification.
96
97         *data*          A type declared with "data".  Also boxed tuples.
98
99         *primitive*     iff it is a built-in type that can't be expressed
100                         in Haskell.
101
102 Currently, all primitive types are unlifted, but that's not necessarily
103 the case.  (E.g. Int could be primitive.)
104
105 Some primitive types are unboxed, such as Int#, whereas some are boxed
106 but unlifted (such as ByteArray#).  The only primitive types that we
107 classify as algebraic are the unboxed tuples.
108
109 examples of type classifications:
110
111 Type            primitive       boxed           lifted          algebraic    
112 -----------------------------------------------------------------------------
113 Int#,           Yes             No              No              No
114 ByteArray#      Yes             Yes             No              No
115 (# a, b #)      Yes             No              No              Yes
116 (  a, b  )      No              Yes             Yes             Yes
117 [a]             No              Yes             Yes             Yes
118
119
120
121         ----------------------
122         A note about newtypes
123         ----------------------
124
125 Consider
126         newtype N = MkN Int
127
128 Then we want N to be represented as an Int, and that's what we arrange.
129 The front end of the compiler [TcType.lhs] treats N as opaque, 
130 the back end treats it as transparent [Type.lhs].
131
132 There's a bit of a problem with recursive newtypes
133         newtype P = MkP P
134         newtype Q = MkQ (Q->Q)
135
136 Here the 'implicit expansion' we get from treating P and Q as transparent
137 would give rise to infinite types, which in turn makes eqType diverge.
138 Similarly splitForAllTys and splitFunTys can get into a loop.  
139
140 Solution: 
141
142 * Newtypes are always represented using TyConApp.
143
144 * For non-recursive newtypes, P, treat P just like a type synonym after 
145   type-checking is done; i.e. it's opaque during type checking (functions
146   from TcType) but transparent afterwards (functions from Type).  
147   "Treat P as a type synonym" means "all functions expand NewTcApps 
148   on the fly".
149
150   Applications of the data constructor P simply vanish:
151         P x = x
152   
153
154 * For recursive newtypes Q, treat the Q and its representation as 
155   distinct right through the compiler.  Applications of the data consructor
156   use a coerce:
157         Q = \(x::Q->Q). coerce Q x
158   They are rare, so who cares if they are a tiny bit less efficient.
159
160 The typechecker (TcTyDecls) identifies enough type construtors as 'recursive'
161 to cut all loops.  The other members of the loop may be marked 'non-recursive'.
162
163
164 %************************************************************************
165 %*                                                                      *
166 \subsection{The data type}
167 %*                                                                      *
168 %************************************************************************
169
170
171 \begin{code}
172 data Type
173   = TyVarTy TyVar       
174
175   | AppTy
176         Type            -- Function is *not* a TyConApp
177         Type            -- It must be another AppTy, or TyVarTy
178                         -- (or NoteTy of these)
179
180   | TyConApp            -- Application of a TyCon, including newtypes *and* synonyms
181         TyCon           --  *Invariant* saturated appliations of FunTyCon and
182                         --      synonyms have their own constructors, below.
183                         -- However, *unsaturated* FunTyCons do appear as TyConApps.  
184                         -- 
185         [Type]          -- Might not be saturated.
186                         -- Even type synonyms are not necessarily saturated;
187                         -- for example unsaturated type synonyms can appear as the 
188                         -- RHS of a type synonym.
189
190   | FunTy               -- Special case of TyConApp: TyConApp FunTyCon [t1,t2]
191         Type
192         Type
193
194   | ForAllTy            -- A polymorphic type
195         TyVar
196         Type    
197
198   | PredTy              -- The type of evidence for a type predictate
199         PredType        -- See Note [PredTy], and Note [Equality predicates]
200         -- NB: A PredTy (EqPred _ _) can appear only as the kind
201         --     of a coercion variable; never as the argument or result
202         --     of a FunTy (unlike ClassP, IParam)
203
204   | NoteTy              -- A type with a note attached
205         TyNote
206         Type            -- The expanded version
207
208 type Kind = Type        -- Invariant: a kind is always
209                         --      FunTy k1 k2
210                         -- or   TyConApp PrimTyCon [...]
211                         -- or   TyVar kv (during inference only)
212                         -- or   ForAll ... (for top-level coercions)
213
214 type SuperKind = Type   -- Invariant: a super kind is always 
215                         --   TyConApp SuperKindTyCon ...
216
217 data TyNote = FTVNote TyVarSet  -- The free type variables of the noted expression
218 \end{code}
219
220 -------------------------------------
221                 Note [PredTy]
222
223 A type of the form
224         PredTy p
225 represents a value whose type is the Haskell predicate p, 
226 where a predicate is what occurs before the '=>' in a Haskell type.
227 It can be expanded into its representation, but: 
228
229         * The type checker must treat it as opaque
230         * The rest of the compiler treats it as transparent
231
232 Consider these examples:
233         f :: (Eq a) => a -> Int
234         g :: (?x :: Int -> Int) => a -> Int
235         h :: (r\l) => {r} => {l::Int | r}
236
237 Here the "Eq a" and "?x :: Int -> Int" and "r\l" are all called *predicates*
238 Predicates are represented inside GHC by PredType:
239
240 \begin{code}
241 data PredType 
242   = ClassP Class [Type]         -- Class predicate
243   | IParam (IPName Name) Type   -- Implicit parameter
244   | EqPred Type Type            -- Equality predicate (ty1 ~ ty2)
245
246 type ThetaType = [PredType]
247 \end{code}
248
249 (We don't support TREX records yet, but the setup is designed
250 to expand to allow them.)
251
252 A Haskell qualified type, such as that for f,g,h above, is
253 represented using 
254         * a FunTy for the double arrow
255         * with a PredTy as the function argument
256
257 The predicate really does turn into a real extra argument to the
258 function.  If the argument has type (PredTy p) then the predicate p is
259 represented by evidence (a dictionary, for example, of type (predRepTy p).
260
261 Note [Equality predicates]
262 ~~~~~~~~~~~~~~~~~~~~~~~~~~
263         forall a b. (a ~ S b) => a -> b
264 could be represented by
265         ForAllTy a (ForAllTy b (FunTy (PredTy (EqPred a (S b))) ...))
266 OR
267         ForAllTy a (ForAllTy b (ForAllTy (c::PredTy (EqPred a (S b))) ...))
268
269 The latter is what we do.  (Unlike for class and implicit parameter
270 constraints, which do use FunTy.)
271
272 Reason:
273         * FunTy is always a *value* function
274         * ForAllTy is discarded at runtime
275
276 We often need to make a "wildcard" (c::PredTy..).  We always use the same
277 name (wildCoVarName), since it's not mentioned.
278
279
280 %************************************************************************
281 %*                                                                      *
282                         TyThing
283 %*                                                                      *
284 %************************************************************************
285
286 Despite the fact that DataCon has to be imported via a hi-boot route, 
287 this module seems the right place for TyThing, because it's needed for
288 funTyCon and all the types in TysPrim.
289
290 \begin{code}
291 data TyThing = AnId     Id
292              | ADataCon DataCon
293              | ATyCon   TyCon
294              | AClass   Class
295
296 instance Outputable TyThing where 
297   ppr = pprTyThing
298
299 pprTyThing :: TyThing -> SDoc
300 pprTyThing thing = pprTyThingCategory thing <+> quotes (ppr (getName thing))
301
302 pprTyThingCategory :: TyThing -> SDoc
303 pprTyThingCategory (ATyCon _)   = ptext SLIT("Type constructor")
304 pprTyThingCategory (AClass _)   = ptext SLIT("Class")
305 pprTyThingCategory (AnId   _)   = ptext SLIT("Identifier")
306 pprTyThingCategory (ADataCon _) = ptext SLIT("Data constructor")
307
308 instance NamedThing TyThing where       -- Can't put this with the type
309   getName (AnId id)     = getName id    -- decl, because the DataCon instance
310   getName (ATyCon tc)   = getName tc    -- isn't visible there
311   getName (AClass cl)   = getName cl
312   getName (ADataCon dc) = dataConName dc
313 \end{code}
314
315
316 %************************************************************************
317 %*                                                                      *
318                 Wired-in type constructors
319 %*                                                                      *
320 %************************************************************************
321
322 We define a few wired-in type constructors here to avoid module knots
323
324 \begin{code}
325 --------------------------
326 -- First the TyCons...
327
328 funTyCon = mkFunTyCon funTyConName (mkArrowKinds [argTypeKind, openTypeKind] liftedTypeKind)
329         -- You might think that (->) should have type (?? -> ? -> *), and you'd be right
330         -- But if we do that we get kind errors when saying
331         --      instance Control.Arrow (->)
332         -- becuase the expected kind is (*->*->*).  The trouble is that the
333         -- expected/actual stuff in the unifier does not go contra-variant, whereas
334         -- the kind sub-typing does.  Sigh.  It really only matters if you use (->) in
335         -- a prefix way, thus:  (->) Int# Int#.  And this is unusual.
336
337
338 tySuperKindTyCon     = mkSuperKindTyCon tySuperKindTyConName
339 coSuperKindTyCon     = mkSuperKindTyCon coSuperKindTyConName
340
341 liftedTypeKindTyCon   = mkKindTyCon liftedTypeKindTyConName
342 openTypeKindTyCon     = mkKindTyCon openTypeKindTyConName
343 unliftedTypeKindTyCon = mkKindTyCon unliftedTypeKindTyConName
344 ubxTupleKindTyCon     = mkKindTyCon ubxTupleKindTyConName
345 argTypeKindTyCon      = mkKindTyCon argTypeKindTyConName
346
347 mkKindTyCon :: Name -> TyCon
348 mkKindTyCon name = mkVoidPrimTyCon name tySuperKind 0
349
350 --------------------------
351 -- ... and now their names
352
353 tySuperKindTyConName      = mkPrimTyConName FSLIT("BOX") tySuperKindTyConKey tySuperKindTyCon
354 coSuperKindTyConName      = mkPrimTyConName FSLIT("COERCION") coSuperKindTyConKey coSuperKindTyCon
355 liftedTypeKindTyConName   = mkPrimTyConName FSLIT("*") liftedTypeKindTyConKey liftedTypeKindTyCon
356 openTypeKindTyConName     = mkPrimTyConName FSLIT("?") openTypeKindTyConKey openTypeKindTyCon
357 unliftedTypeKindTyConName = mkPrimTyConName FSLIT("#") unliftedTypeKindTyConKey unliftedTypeKindTyCon
358 ubxTupleKindTyConName     = mkPrimTyConName FSLIT("(#)") ubxTupleKindTyConKey ubxTupleKindTyCon
359 argTypeKindTyConName      = mkPrimTyConName FSLIT("??") argTypeKindTyConKey argTypeKindTyCon
360 funTyConName              = mkPrimTyConName FSLIT("(->)") funTyConKey funTyCon
361
362 mkPrimTyConName occ key tycon = mkWiredInName gHC_PRIM (mkOccNameFS tcName occ) 
363                                               key 
364                                               (ATyCon tycon)
365                                               BuiltInSyntax
366         -- All of the super kinds and kinds are defined in Prim and use BuiltInSyntax,
367         -- because they are never in scope in the source
368
369 ------------------
370 -- We also need Kinds and SuperKinds, locally and in TyCon
371
372 kindTyConType :: TyCon -> Type
373 kindTyConType kind = TyConApp kind []
374
375 liftedTypeKind   = kindTyConType liftedTypeKindTyCon
376 unliftedTypeKind = kindTyConType unliftedTypeKindTyCon
377 openTypeKind     = kindTyConType openTypeKindTyCon
378 argTypeKind      = kindTyConType argTypeKindTyCon
379 ubxTupleKind     = kindTyConType ubxTupleKindTyCon
380
381 mkArrowKind :: Kind -> Kind -> Kind
382 mkArrowKind k1 k2 = FunTy k1 k2
383
384 mkArrowKinds :: [Kind] -> Kind -> Kind
385 mkArrowKinds arg_kinds result_kind = foldr mkArrowKind result_kind arg_kinds
386
387 tySuperKind, coSuperKind :: SuperKind
388 tySuperKind = kindTyConType tySuperKindTyCon 
389 coSuperKind = kindTyConType coSuperKindTyCon 
390
391 isTySuperKind (NoteTy _ ty)    = isTySuperKind ty
392 isTySuperKind (TyConApp kc []) = kc `hasKey` tySuperKindTyConKey
393 isTySuperKind other            = False
394
395 isCoSuperKind :: SuperKind -> Bool
396 isCoSuperKind (NoteTy _ ty)    = isCoSuperKind ty
397 isCoSuperKind (TyConApp kc []) = kc `hasKey` coSuperKindTyConKey
398 isCoSuperKind other            = False
399
400 -------------------
401 -- Lastly we need a few functions on Kinds
402
403 isLiftedTypeKindCon tc    = tc `hasKey` liftedTypeKindTyConKey
404
405 isLiftedTypeKind :: Kind -> Bool
406 isLiftedTypeKind (TyConApp tc []) = isLiftedTypeKindCon tc
407 isLiftedTypeKind other            = False
408
409 isCoercionKind :: Kind -> Bool
410 -- All coercions are of form (ty1 ~ ty2)
411 -- This function is here rather than in Coercion, 
412 -- because it's used in a knot-tied way to enforce invariants in Var
413 isCoercionKind (NoteTy _ k)         = isCoercionKind k
414 isCoercionKind (PredTy (EqPred {})) = True
415 isCoercionKind other                = False
416
417 coVarPred :: CoVar -> PredType
418 coVarPred tv
419   = ASSERT( isCoVar tv )
420     case tyVarKind tv of
421         PredTy eq -> eq         -- There shouldn't even be a NoteTy in the way
422         other     -> pprPanic "coVarPred" (ppr tv $$ ppr other)
423 \end{code}
424
425
426
427 %************************************************************************
428 %*                                                                      *
429 \subsection{The external interface}
430 %*                                                                      *
431 %************************************************************************
432
433 @pprType@ is the standard @Type@ printer; the overloaded @ppr@ function is
434 defined to use this.  @pprParendType@ is the same, except it puts
435 parens around the type, except for the atomic cases.  @pprParendType@
436 works just by setting the initial context precedence very high.
437
438 \begin{code}
439 data Prec = TopPrec     -- No parens
440           | FunPrec     -- Function args; no parens for tycon apps
441           | TyConPrec   -- Tycon args; no parens for atomic
442           deriving( Eq, Ord )
443
444 maybeParen :: Prec -> Prec -> SDoc -> SDoc
445 maybeParen ctxt_prec inner_prec pretty
446   | ctxt_prec < inner_prec = pretty
447   | otherwise              = parens pretty
448
449 ------------------
450 pprType, pprParendType :: Type -> SDoc
451 pprType       ty = ppr_type TopPrec   ty
452 pprParendType ty = ppr_type TyConPrec ty
453
454 pprTypeApp :: NamedThing a => a -> SDoc -> [Type] -> SDoc
455 -- The first arg is the tycon; it's used to arrange printing infix 
456 -- if it looks like an operator
457 -- Second arg is the pretty-printed tycon
458 pprTypeApp tc pp_tc tys = ppr_type_app TopPrec (getName tc) pp_tc tys
459
460 ------------------
461 pprPred :: PredType -> SDoc
462 pprPred (ClassP cls tys) = pprClassPred cls tys
463 pprPred (IParam ip ty)   = ppr ip <> dcolon <> pprType ty
464 pprPred (EqPred ty1 ty2) = sep [ppr ty1, nest 2 (ptext SLIT("~")), ppr ty2]
465 pprClassPred :: Class -> [Type] -> SDoc
466 pprClassPred clas tys = ppr_type_app TopPrec (getName clas) (ppr clas) tys
467
468 pprTheta :: ThetaType -> SDoc
469 pprTheta theta = parens (sep (punctuate comma (map pprPred theta)))
470
471 pprThetaArrow :: ThetaType -> SDoc
472 pprThetaArrow theta 
473   | null theta = empty
474   | otherwise  = parens (sep (punctuate comma (map pprPred theta))) <+> ptext SLIT("=>")
475
476 ------------------
477 instance Outputable Type where
478     ppr ty = pprType ty
479
480 instance Outputable PredType where
481     ppr = pprPred
482
483 instance Outputable name => OutputableBndr (IPName name) where
484     pprBndr _ n = ppr n -- Simple for now
485
486 ------------------
487         -- OK, here's the main printer
488
489 pprKind = pprType
490 pprParendKind = pprParendType
491
492 ppr_type :: Prec -> Type -> SDoc
493 ppr_type p (TyVarTy tv)       = ppr tv
494 ppr_type p (PredTy pred)      = ifPprDebug (ptext SLIT("<pred>")) <> (ppr pred)
495 ppr_type p (NoteTy other ty2) = ifPprDebug (ptext SLIT("<note>")) <> ppr_type p ty2
496 ppr_type p (TyConApp tc tys)  = ppr_tc_app p tc tys
497
498 ppr_type p (AppTy t1 t2) = maybeParen p TyConPrec $
499                            pprType t1 <+> ppr_type TyConPrec t2
500
501 ppr_type p ty@(ForAllTy _ _)       = ppr_forall_type p ty
502 ppr_type p ty@(FunTy (PredTy _) _) = ppr_forall_type p ty
503
504 ppr_type p (FunTy ty1 ty2)
505   = -- We don't want to lose synonyms, so we mustn't use splitFunTys here.
506     maybeParen p FunPrec $
507     sep (ppr_type FunPrec ty1 : ppr_fun_tail ty2)
508   where
509     ppr_fun_tail (FunTy ty1 ty2) = (arrow <+> ppr_type FunPrec ty1) : ppr_fun_tail ty2
510     ppr_fun_tail other_ty        = [arrow <+> pprType other_ty]
511
512 ppr_forall_type :: Prec -> Type -> SDoc
513 ppr_forall_type p ty
514   = maybeParen p FunPrec $
515     sep [pprForAll tvs, pprThetaArrow ctxt, pprType tau]
516   where
517     (tvs,  rho) = split1 [] ty
518     (ctxt, tau) = split2 [] rho
519
520     -- We need to be extra careful here as equality constraints will occur as
521     -- type variables with an equality kind.  So, while collecting quantified
522     -- variables, we separate the coercion variables out and turn them into
523     -- equality predicates.
524     split1 tvs (ForAllTy tv ty) 
525       | not (isCoVar tv)     = split1 (tv:tvs) ty
526     split1 tvs (NoteTy _ ty) = split1 tvs ty
527     split1 tvs ty            = (reverse tvs, ty)
528  
529     split2 ps (NoteTy _ arg     -- Rather a disgusting case
530                `FunTy` res)         = split2 ps (arg `FunTy` res)
531     split2 ps (PredTy p `FunTy` ty) = split2 (p:ps) ty
532     split2 ps (ForAllTy tv ty) 
533         | isCoVar tv                = split2 (coVarPred tv : ps) ty
534     split2 ps (NoteTy _ ty)         = split2 ps ty
535     split2 ps ty                    = (reverse ps, ty)
536
537 ppr_tc_app :: Prec -> TyCon -> [Type] -> SDoc
538 ppr_tc_app p tc [] 
539   = ppr_tc tc
540 ppr_tc_app p tc [ty] 
541   | tc `hasKey` listTyConKey = brackets (pprType ty)
542   | tc `hasKey` parrTyConKey = ptext SLIT("[:") <> pprType ty <> ptext SLIT(":]")
543   | tc `hasKey` liftedTypeKindTyConKey   = ptext SLIT("*")
544   | tc `hasKey` unliftedTypeKindTyConKey = ptext SLIT("#")
545   | tc `hasKey` openTypeKindTyConKey     = ptext SLIT("(?)")
546   | tc `hasKey` ubxTupleKindTyConKey     = ptext SLIT("(#)")
547   | tc `hasKey` argTypeKindTyConKey      = ptext SLIT("??")
548
549 ppr_tc_app p tc tys
550   | isTupleTyCon tc && tyConArity tc == length tys
551   = tupleParens (tupleTyConBoxity tc) (sep (punctuate comma (map pprType tys)))
552   | otherwise
553   = ppr_type_app p (getName tc) (ppr_naked_tc tc) tys
554
555 ppr_type_app :: Prec -> Name -> SDoc -> [Type] -> SDoc
556 ppr_type_app p tc pp_tc tys
557   | is_sym_occ          -- Print infix if possible
558   , [ty1,ty2] <- tys    -- We know nothing of precedence though
559   = maybeParen p FunPrec (sep [ppr_type FunPrec ty1, 
560                                pp_tc <+> ppr_type FunPrec ty2])
561   | otherwise
562   = maybeParen p TyConPrec (hang paren_tc 2 (sep (map pprParendType tys)))
563   where
564     is_sym_occ = isSymOcc (getOccName tc)
565     paren_tc | is_sym_occ = parens pp_tc
566              | otherwise  = pp_tc
567
568 ppr_tc :: TyCon -> SDoc
569 ppr_tc tc = parenSymOcc (getOccName tc) (ppr_naked_tc tc)
570
571 ppr_naked_tc :: TyCon -> SDoc   -- No brackets for SymOcc
572 ppr_naked_tc tc 
573   = pp_nt_debug <> ppr tc
574   where
575    pp_nt_debug | isNewTyCon tc = ifPprDebug (if isRecursiveTyCon tc 
576                                              then ptext SLIT("<recnt>")
577                                              else ptext SLIT("<nt>"))
578                | otherwise     = empty
579
580 -------------------
581 pprForAll []  = empty
582 pprForAll tvs = ptext SLIT("forall") <+> sep (map pprTvBndr tvs) <> dot
583
584 pprTvBndr tv | isLiftedTypeKind kind = ppr tv
585              | otherwise             = parens (ppr tv <+> dcolon <+> pprKind kind)
586              where
587                kind = tyVarKind tv
588 \end{code}
589