How to declare polymorphic instances for higher-kinded types?

Herbert Valerio Riedel hvr at
Mon Mar 5 13:14:45 CET 2012

Andres Löh <andres at> writes:

> Here's a way that seems to work for me. I haven't tested in detail.
> There may be problems, or also easier ways to achieve the same. The
> DataKinds extension isn't essential. I've just used it for fun.

looks interesting

If I get it right, the trick is to use a *-kinded (instead of a
*->*-kinded) argument for the class & instances and have a "type
function" that is able to phantom-retag an already applied
type-constructor `Foo_ Unres` to a differently applied type-constructor
`Foo_ Res`.

The only thing that disturbs me is that I have to define explicit
boilerplate type family declarations for all twenty or so
non-polymorphic instances which'd look always the same, i.e.

type ResFun (t r) a = t a
type ResArg (t r) a = t ~ a

...could that be defined as an override-able default somehow?


More information about the Glasgow-haskell-users mailing list