#13901 closed feature request (duplicate)

Lift the "Illegal polymorphic type" restriction on type families

Reported by: RyanGlScott Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 8.0.1
Keywords: TypeFamilies Cc: Iceland_jack, int-index
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: #9269, #11962 Differential Rev(s):
Wiki Page:


Currently, I can do this:

type Foo = forall a. Maybe a

But if I try to refactor this to an equivalent type family:

type family Foo where
  Foo = forall a. Maybe a

Then GHC complains:

    • Illegal polymorphic type: forall a. Maybe a
    • In the equations for closed type family ‘Foo’
      In the type family declaration for ‘Foo’

We should lift this restriction. This would be necessary, for instance, to implement #11962.

Change History (6)

comment:1 Changed 13 months ago by Iceland_jack

Cc: Iceland_jack added

comment:2 Changed 13 months ago by goldfire

This isn't so easy. With type families, there are potentially many right-hand sides. Some may have polymorphism, and some may not. And we might not know which is chosen until we get to the constraint solver. When the constraint-generation algorithm looks at something with type Foo, does it add a wrapper for instantiating forall a. Maybe a? Or not? Impossible to know. This all smells a bit like impredicativity.

comment:3 Changed 12 months ago by int-index

Cc: int-index added

comment:4 Changed 12 months ago by Artyom.Kazak

does it add a wrapper for instantiating

What wrapper? (Just curious.)

comment:5 Changed 12 months ago by goldfire

The reference to wrapper is more of an implementation detail. GHC uses a HsWrapper type to denote things that happen to expressions (instantiations, type abstractions, dictionary applications, etc.) that are invisible in user-written Haskell. That's all I was referring to there.

comment:6 Changed 11 months ago by RyanGlScott

Resolution: duplicate
Status: newclosed

This is a duplicate of #9269.

Note: See TracTickets for help on using tickets.