haskell - How to make impredicative types work with type classes -


i seeing impredicativetypes , wanted see them. when ran feel strange behavior when comes interaction typeclasses.

:t mempty mempty :: forall a. monoid =>  :t right right :: forall b. b -> either b 

so figured combine them make impredicatively typed expression:

:t right mempty right mempty :: forall b. monoid b => either b 

looks extension not infer impredicative types, doesn't seem unreasonable, know type inference not possible in general case when start adding features this.

so decided make fact wanted impredicative type explicit:

:t right mempty :: forall a. either (forall b. monoid b => b) 

which me seemed reasonable, literally pasting on b in right type signature type of mempty, , not lifting forall.

but give me following error:

no instance (monoid (forall b. monoid b => b)) 

which seems rather absurd. since every monoid instance of monoid definition.

can explain me going on here? issue difficult or impossible decide on 1 instance when using type, , ghc means "no unambiguous / decidable instance for..." rather "no instance..."?

as side note when take typeclasses out of situation appears work ok:

:t right undefined :: forall a. either (forall b. b) 

type checks , gives me impredicative type specified.

so question isn't marked unanswered guess reiterate said in comments.

basically impredicativetypes totally unsupported, , no 1 knows how should work. trying meaningful in current state bad idea. answer just: "don't try that".


Comments