
#15181: Levity Polymorphic type signatures in GHC.Prim -------------------------------------+------------------------------------- Reporter: andrewthad | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.2.2 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- 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 }}}
Similarly, `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. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15181 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler