External Publication
Visit Post

Synthesizing `RuntimeRep`-indexed type class instances in a GHC plugin to simulate monomorphization

Haskell Community [Unofficial] March 11, 2026
Source

It is possible to do partial specialisation. See for example Sixten.

A representation-polymorphic function accepts a witness of the representation, such as a log2 size (alignment, &c.), and uses that to deal with any values of that representation at runtime. This is a middle ground that allows separate compilation without giving up unboxing altogether.

Likewise, in an existential, you would store this witness, in much the same way as a typeclass dictionary. Perhaps it could even reuse a lot of the same machinery. For example, when you see forall (r :: RuntimeRep), introduce a constraint IsRuntimeRep# r, whose dictionary is a Word# holding the size.

Discussion in the ATmosphere

Loading comments...