Note [Desugaring coerce as cast]
We want the user to express a rule saying roughly “mapping a coercion over a list can be replaced by a coercion”. But the cast operator of Core (▷) cannot be written in Haskell. So we use `coerce` for that (#2110). The user writes map coerce = coerce as a RULE, and this optimizes any kind of mapped' casts away, including `map MkNewtype`. For that we replace any forall'ed `c :: Coercible a b` value in a RULE by corresponding `co :: a ~#R b` and wrap the LHS and the RHS in `let c = MkCoercible co in ...`. This is later simplified to the desired form by simpleOptExpr (for the LHS) resp. the simplifiers (for the RHS). See also Note [Getting the map/coerce RULE to work] in GHC.Core.SimpleOpt.
References 1
- Getting the map/coerce RULE to work GHC.Core.SimpleOpt
Referenced by 3
- Unfold compulsory unfoldings in RULE LHSs GHC.Core.SimpleOpt
- GHC.Core.SimpleOpt call site
- GHC.HsToCore call site