Indeed, we have it already, or maybe half of it.
It seems that HKD is using a type family on Rep
-- | Calculate the "partial representation" of a type.
type HKD_ (f :: Type -> Type) (structure :: Type)
= GHKD_ f (Rep structure)
-- | Calculate the "partial representation" of a generic rep.
type family GHKD_ (f :: Type -> Type) (rep :: Type -> Type)
= (output :: Type -> Type) | output -> f rep where
GHKD_ f (M1 index meta inner) = M1 index meta (GHKD_ f inner)
GHKD_ f (left :*: right) = GHKD_ f left :*: GHKD_ f right
GHKD_ f (K1 index value) = K1 index (f value)
GHKD_ f (left :+: right) = GHKD_ f left :+: GHKD_ f right
Which is really clever. If I am correct then the resulting type of HKD
is not vanilla type but of the Generic genre (a mix of M1
and :*:
etc …). So you don’t have a nice plain record with field accessor
(this i why I guess HKD as to use label to acces fields) and I’m not sure if you can do pattern matching.
To transform fully a type we would need the opposite of Rep
, something which create a plain type from it’s generic representation (unless it already exists somewhere).