Search code examples
haskellhigher-rank-types

Illegal polymorphic or qualified type in Haskell


Why is Haskell complaining when trying to parse this type signature?

f :: (a,s) -> (forall r.(r -> (a,r)),s)

Solution

  • Haskell does not support impredicative types, and in particular does not allow forall to appear under any type constructor (except ->).

    For example, Maybe (forall a. a), [forall a. a->a], ((forall a. a), Bool) are forbidden.

    Use a newtype wrapper if that's what you want.

    newtype T = T (forall a. a->a)
    foo :: [T] -- OK
    foo = [T id]