Levity Polymorphic type signatures in GHC.Prim
Some of the type signatures in the haddocks for GHC.Prim are misleading. Here are a few:
unsafeCoerce# :: a -> b mkWeak# :: o -> b -> (State# RealWorld -> (#State# RealWorld, c#)) -> State# RealWorld -> (#State# RealWorld, Weak# b#) raise# :: b -> o
The type signatures for these lead one to believe that all of the arguments must be **lifted** types, but this is not actually the case. For example,
raise# is levity polymorphic in its returned value and should actually have the type:
raise# :: forall (r :: RuntimeRep) (o :: TYPE r). b -> o
It's not just the haddocks that show an inaccurate type. Even in GHCi, we get this:
>>> :set -XMagicHash >>> :set -fprint-explicit-kinds >>> :set -fprint-explicit-runtime-reps >>> import GHC.Exts >>> :t raise# raise# :: b -> a
unsafeCoerce# is levity polymorphic in both types. Unfortunately,
mkWeak# is more difficult to assign a correct type to. It should be possible for it to be broken into two separate functions (which each do the exact same thing), one of which operates on values of type
LiftedRep and other on
UnliftedRep. But this would be a breaking change, and it may not be worth the breakage it would introduce.
At the very least, I feel like fixing
raise# is worthwhile, since it wouldn't break anything.