Error GHC-91510: illegal polymorphic type
Haskell Community [Unofficial]
June 21, 2026
I’m working on constrained categories, and I want to write the following:
type Category :: (k -> k -> Type) -> Constraint
class Category cat where
type Objects cat (x :: k) :: Constraint
type Objects cat x = ()
id :: (Objects cat x) => cat x x
(.) ::
(Objects cat x, Objects cat y, Objects cat z) => cat y z -> cat x y -> cat x z
instance Category (->) where
id :: x -> x
id x = x
(.) :: (y -> z) -> (x -> y) -> x -> z
y_z . x_y = \x -> y_z (x_y x)
That’s all well and good, but then I encountered an undocumented error while trying to extend this to natural transformations:
type Transform ::
(k -> k -> Type) ->
(j -> k) ->
(j -> k) ->
Type
newtype Transform cat f g = Transform
{transform :: forall x. cat (f x) (g x)}
instance (Category cat) => Category (Transform cat) where
type Objects (Transform cat) f = forall x. Objects cat (f x) -- GHC-91510
id :: Transform cat f f
id = Transform id
(.) :: Transform cat g h -> Transform cat f g -> Transform cat f h
Transform g_h . Transform f_g = Transform (g_h . f_g)
The error text is
• Illegal polymorphic type: forall (x :: k2). Objects cat (f x)
• In the type instance declaration for ‘Objects’
In the instance declaration for ‘Category (Transform cat)’
Why is this polymorphic type illegal? It’s just a quantified constraint. What can be done to legalize it?
Discussion in the ATmosphere