[source]

compiler/hsSyn/HsUtils.hs

Note [Kind signatures in typeToLHsType]

[note link]

There are types that typeToLHsType can produce which require explicit kind signatures in order to kind-check. Here is an example from #14579:

– type P :: forall {k} {t :: k}. Proxy t type P = ‘Proxy

– type Wat :: forall a. Proxy a -> * newtype Wat (x :: Proxy (a :: Type)) = MkWat (Maybe a)

deriving Eq

—type Wat2 :: forall {a}. Proxy a -> * type Wat2 = Wat

– type Glurp :: * -> * newtype Glurp a = MkGlurp (Wat2 (P :: Proxy a))

deriving Eq

The derived Eq instance for Glurp (without any kind signatures) would be:

instance Eq a => Eq (Glurp a) where
  (==) = coerce @(Wat2 P  -> Wat2 P  -> Bool)
                @(Glurp a -> Glurp a -> Bool)
                (==) :: Glurp a -> Glurp a -> Bool

(Where the visible type applications use types produced by typeToLHsType.)

The type P (in Wat2 P) has an underspecified kind, so we must ensure that typeToLHsType ascribes it with its kind: Wat2 (P :: Proxy a). To accomplish this, whenever we see an application of a tycon to some arguments, we use the tyConAppNeedsKindSig function to determine if it requires an explicit kind signature to resolve some ambiguity. (See Note Note [When does a tycon application need an explicit kind signature?] for a more detailed explanation of how this works.)

Note that we pass True to tyConAppNeedsKindSig since we are generated code with visible kind applications, so even specified arguments count towards injective positions in the kind of the tycon.

Note [Collect binders only after renaming]

[note link]

These functions should only be used on HsSyn after the renamer, to return a [Name] or [Id]. Before renaming the record punning and wild-card mechanism makes it hard to know what is bound. So these functions should not be applied to (HsSyn RdrName)

Note [Unlifted id check in isUnliftedHsBind]

[note link]

The function isUnliftedHsBind is used to complain if we make a top-level binding for a variable of unlifted type.

Such a binding is illegal if the top-level binding would be unlifted; but also if the local letrec generated by desugaring AbsBinds would be. E.g.

f :: Num a => (# a, a #) g :: Num a => a -> a f = …g… g = …g…

The top-level bindings for f,g are not unlifted (because of the Num a =>), but the local, recursive, monomorphic bindings are:

t = /\a \(d:Num a).
   letrec fm :: (# a, a #) = ...g...
          gm :: a -> a = ...f...
   in (fm, gm)

Here the binding for ‘fm’ is illegal. So generally we check the abe_mono types.

BUT we have a special case when abs_sig is true;
see HsBinds Note [The abs_sig field of AbsBinds]

————— Bindings ————————–

Note [SrcSpan for binders]

[note link]

When extracting the (Located RdrNme) for a binder, at least for the main name (the TyCon of a type declaration etc), we want to give it the @SrcSpan@ of the whole /declaration/, not just the name itself (which is how it appears in the syntax tree). This SrcSpan (for the entire declaration) is used as the SrcSpan for the Name that is finally produced, and hence for error messages. (See #8607.)

Note [Binders in family instances]

[note link]

In a type or data family instance declaration, the type constructor is an occurrence not a binding site

type instance T Int = Int -> Int – No binders data instance S Bool = S1 | S2 – Binders are S1,S2