External Publication
Visit Post

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

Haskell Community [Unofficial] March 9, 2026
Source

A good background paper is Levity polymorphism. Worth reading if you are digging into this.

I can’t comment about compiler support until I understand the proposed solution, the one you attribute to Ed K. The problem is a fundamental one. If we have

f :: Num a => a -> a
f x = ...lots of code...

Now if we want to apply f to an unboxed int, thus (f @Double# 19882.234#) we are stuck. The gobs of compiled matchine code for f manipulates boxed pointers, but we want compiled code that manipulates unboxed floats. Different machine instructions!

The only solutions I know are

  • Box the Double# before calling f – but that negates the whole point, which is to manipulate unboxed values exclusively.
  • Make a copy of the source code for f, specifically for Double#, and compile that. Now we have two versions of f. That’s fine but it’s hard to know which types to specialise f for (there are an infinite number of unboxed types). .NET does this, but GHC currently makes no attempt to do so.

It’d be worth having a clear design before thinking about implementation strategies.

Discussion in the ATmosphere

Loading comments...