Skip to content

UNPACK support for existentials

Consider

data Foo = forall a. Show a => Foo !a !a

data Bar = Bar {-# UNPACK #-} !Foo

The UNPACK pragma should really be able to unpack the Foo field, so that (implementation-wise) it would be as if you'd declared Bar thus:

data Bar = forall a. Show a => Bar !a !a
     -- The worker for Bar

$WBar :: Foo -> Bar   -- The wrapper for Bar
$WBar (Foo @a (d :: Show a) (x :: a) (y :: a))
  = Bar @a d x y

But currently we get

Ignoring unusable UNPACK pragma on the first argument of ‘Bar’

Suggested by Nicholas Clarke here.

Vaguely related tickets: #7647, #9214 (closed). But unlike those ones, this one looks quite feasible to me.

Fixing this would require quite a bit of new plumbing. E.g. the existential type variable of the worker and wrapper would differ, which is not true today. But morally it's the Right Thing.

I'd be interested in actual use-cases.

Edited by Sebastian Graf
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information