Polymorphic unlifted bindings without a signature
Consider
{-# LANGUAGE UnliftedDatatypes #-}
module M where
import GHC.Exts
import Data.Kind
type T :: Type -> UnliftedType
data T a = MkT ()
f :: () -> T b
f _ = let x = MkT () in x
g :: () -> T b
g _ = let x :: T a; x = MkT () in x
g
is accepted, while f
is rejected:
M.hs:11:11: error: [GHC-20036]
You can't mix polymorphic and unlifted bindings: x = MkT ()
Suggested fix: Add a type signature.
|
11 | f _ = let x = MkT () in x
| ^^^^^^^^^^
This is surprising. The type of x
should be the same in f
and g
. In both cases we are mixing polymorphic and unlifted bindings. I think we should just accept f
.
Another variant is
h :: () -> T b
h u = let x = MkT u in x
This is rejected normally, but accepted with MonoLocalBinds. In the case of f
, enabling MonoLocalBinds has no effect, because the rhs in x = MkT ()
doesn't refer to any free variables.
Originally, this error was created in the context of T6078, which boils down to
i :: Ptr Int
i = let u :: Ptr a
v :: Addr#
u@(Ptr v) = undefined
in u
Here, there is a type signature, just like in g
. But unlike g
, the type signature doesn't help and this is rejected. Desugaring pattern bindings is more complex and I'm not sure if we should accept i
. For example, would we get v :: forall a. Addr#
in the desugared program? But at least we should accept f
.