Note [Required foralls in Core]
Consider the CoreExpr (Lam a e) where `a` is a TyVar, and (e::e_ty). It has type forall a. e_ty Note the Specified visibility of (forall a. e_ty); the Core type just isn't able to express more than one visiblity, and we pick `Specified`. See `exprType` and `mkLamType` in GHC.Core.Utils, and `GHC.Type.Var.coreTyLamForAllTyFlag`. So how can we ever get a term of type (forall a -> e_ty)? Answer: /only/ via a cast built with ForAllCo. See `GHC.Core.Coercion.mkForAllVisCos`, `GHC.Tc.Types.Evidence.mkWpForAllCast` and `GHC.Core.Make.mkCoreTyLams`. This does not seem very satisfying, but it does the job. An alternative would be to put a visibility flag into `Lam` (a huge change), or into a `TyVar` (a more plausible change), but we leave that for the future. See also Note [ForAllTy and type equality] in GHC.Core.TyCo.Compare.
References 1
- ForAllTy and type equality GHC.Core.TyCo.Compare
Referenced by 10
- GHC.Core.Coercion call site
- Flag cast in data con wrappers GHC.Core.DataCon
- DataCon user type variable binders GHC.Core.DataCon
- GHC.Core.Make call site
- GHC.Core.Opt.Arity call site
- ForAllCo GHC.Core.TyCo.Rep
- GHC.Core.Utils call site
- GHC.Tc.Types.Evidence call site
- GHC.Tc.Utils.Instantiate call site
- Language.Haskell.Syntax.Specificity call site