HsWrappers are produced by the typechecker to insert pieces of Core syntax.
For example:
User writes:
id False. Typechecker elaborates toid @Bool Falseusing WpTyApp.User writes:
compare True False. Typechecker elaborates tocompare $dOrdBool True Falseusing WpEvApp.
A wrapper can be thought of as a function CoreExpr -> CoreExpr which
transforms Core syntax by elaboration; we usually write this as
expr ↦ wrap[expr]. We often write a wrapper as an "expression with a hole",
e.g. WpTyApp Int is hole @Int.
NOTATION ~~>: if wrap[ e::t1 ] :: t2, we write the type of wrap
as wrap :: t1 ~~> t2.
Constructors
WpHoleThe identity HsWrapper (similar to the
Reflcoercion).WpSubType HsWrapperWpSubType wpis the same aswp, but with extra invariants. See Note Deep subsumption and WpSubTypeWpCompose HsWrapper HsWrapperWpFun(WpFun mult_co arg_wrap res_wrap t1 t2)[e] = (x :: exp_arg). res_wrap[ e arg_wrap[x] ]INVARIANT: both input and output types of arg_wrap have a fixed runtime-rep See Note [WpFun-FRR-INVARIANT]
Typing rules: given: -
mult_co :: act_mult ~ exp_mult-arg_wrap :: exp_arg ~~> act_arg-res_wrap :: act_res ~~> exp_resthenWpFun mult_co arg_wrap res_wrap :: (act_arg %act_mult -> arg_res) ~~> (exp_arg %exp_mult -> exp_res).This isn't the same as for
mkFunCo, but it has to be this way because we can't usemkSymCoto flip around theseHsWrappers.NB: a WpFun is always for type-like function arrows; no constraints.
Use mkWpFun to construct such a wrapper.
WpCast TcCoercionRA cast:
holecastcoWpEvLam EvVarEvidence abstraction
d. hole, wheredis an evidence variableWpEvApp EvTermhole d, whered@ is evidence for a constraintWpTyLam TyVarType abstraction
a. hole, whereais a type/kind variable (not a coercion variable)WpTyApp KindOrTypeType application
hole t, wheretis a type/kind (not a coercion)WpLet TcEvBinds
Instances5Data, Semigroup, Monoid, Outputable, ToHie
Data HsWrapperDefined in ghc-10.0.0.20260917 · GHC.Tc.Types.EvidenceSemigroup HsWrapperDefined in ghc-10.0.0.20260917 · GHC.Tc.Types.EvidenceThe Semigroup instance is a bit fishy, since
WpCompose, as a data constructor, is "syntactic" and not associative. Concretely, ifa,b, andcaren'tWpHole:(a <> b) <> c ?= a <> (b <> c)>
(a `WpCompose` b) `WpCompose` c /= @ a `WpCompose` (b `WpCompose` c)However these two associations are are "semantically equal" in the sense that they produce equal functions when passed to
GHC.HsToCore.Binds.dsHsWrapper.Monoid HsWrapperDefined in ghc-10.0.0.20260917 · GHC.Tc.Types.EvidenceOutputable HsWrapperDefined in ghc-10.0.0.20260917 · GHC.Tc.Types.EvidenceToHie (LocatedA HsWrapper)Defined in ghc-10.0.0.20260917 · GHC.Iface.Ext.Ast