{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreife6fhupwg2brwokex4nlsvcfbvx4p7dvvwurwcwssdblkuumie5q",
    "uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3mosvnv5rnca2"
  },
  "path": "/t/error-ghc-91510-illegal-polymorphic-type/14304#post_1",
  "publishedAt": "2026-06-21T16:57:52.000Z",
  "site": "https://discourse.haskell.org",
  "tags": [
    "undocumented error"
  ],
  "textContent": "I’m working on constrained categories, and I want to write the following:\n\n\n    type Category :: (k -> k -> Type) -> Constraint\n    class Category cat where\n      type Objects cat (x :: k) :: Constraint\n      type Objects cat x = ()\n      id :: (Objects cat x) => cat x x\n      (.) ::\n        (Objects cat x, Objects cat y, Objects cat z) => cat y z -> cat x y -> cat x z\n\n    instance Category (->) where\n      id :: x -> x\n      id x = x\n      (.) :: (y -> z) -> (x -> y) -> x -> z\n      y_z . x_y = \\x -> y_z (x_y x)\n\n\nThat’s all well and good, but then I encountered an undocumented error while trying to extend this to natural transformations:\n\n\n    type Transform ::\n      (k -> k -> Type) ->\n      (j -> k) ->\n      (j -> k) ->\n      Type\n    newtype Transform cat f g = Transform\n      {transform :: forall x. cat (f x) (g x)}\n\n    instance (Category cat) => Category (Transform cat) where\n      type Objects (Transform cat) f = forall x. Objects cat (f x) -- GHC-91510\n      id :: Transform cat f f\n      id = Transform id\n      (.) :: Transform cat g h -> Transform cat f g -> Transform cat f h\n      Transform g_h . Transform f_g = Transform (g_h . f_g)\n\n\nThe error text is\n\n\n    • Illegal polymorphic type: forall (x :: k2). Objects cat (f x)\n    • In the type instance declaration for ‘Objects’\n      In the instance declaration for ‘Category (Transform cat)’\n\n\nWhy is this polymorphic type illegal? It’s just a quantified constraint. What can be done to legalize it?",
  "title": "Error GHC-91510: illegal polymorphic type"
}