Skip to content

LiftPK: a poly-kinded type lifting operator #10758

Closed
@OlivierBlanvillain

Description

@OlivierBlanvillain

As suggested by @abgruszecki in #7389, we should investigate adding a primitive match type to lift * -> *-kinded operators to arbitrary kinds.

Instead of creating special HeadPK and TailPK primitive match types (Head and Tail from Miles' post above), I think it > would be feasible to instead have a LiftPK primitive (lift poly-kinded)
which allows lifting any type operator of kind * -> * to operate on types of arbitrary kinds, and thus allows defining HeadPK and TailPK. The benefit is that LiftPK allows making all type operators poly-kinded, instead of special-casing Head and Tail, and doesn't seem significantly harder to define. It would behave as follows:

type LiftPK[[]] = ... // compiler-provided
type HeadPK[t] = LiftPK[Head][t] // consistent behaviour with Miles' Head
Head[(1,2,3)] === 1
HeadPK[(1,2,3)] === 1
HeadPK[[t] => (t, 2, 3)]] === [t] => t
type TailPK[t] = LiftPK[Tail][t] // similarly, has behaviour consistent with Tail from the preceding post

As for compiler implementation (and probably as a reminer for @OlivierBlanvillain), LiftPK should be implementable by inventing an abstract type for each type parameter, replacing type parameter references with those types, reducing match type (if there's any to be reduced) and undoing the type parameter substitution.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions