WIP: unboxed classes
In this MR I'm currently experimenting with the following:
-
For newtype-like classes, allow the class field to be representation-polymorphic, mirrorring
-XUnliftedNewtypes
.-
This enables unboxed implicit parameters.
-
This allows users to introduce classes whose return kind is
CONSTRAINT r
, for anr
which is different fromLiftedRep
.
-
-
For datacon-like classes:
a. Allow the return kind of the class to be
CONSTRAINT UnliftedRep
, as with-XUnliftedDataTypes
.b. Allow unlifted/unboxed methods.
(1) seems rather straightforward and doesn't seem to be causing undue trouble to GHC. I think this is a rather compelling application of representation-polymorphic newtypes.
(2a) runs into trouble with instances, as the class instance dictionary is now an unlifted type (if the instance has no context), and we can't have top-level unlifted bindings.
(2b) runs into trouble when defining the class itself, because GHC generates unlifted top-level Id
s for its unlifted class methods (also putting them in the compulsory unfolding of the instance DFunId
). I think it should be possible to make these local bindings in a let clause, but the compulsory unfolding of the DFunId
complicates things somewhat.