Opened 5 years ago

Closed 4 years ago

#10390 closed bug (fixed)

Constraint order must match with RankNTypes

Reported by: crockeea Owned by:
Priority: low Milestone: 7.10.3
Component: Compiler Version: 7.8.4
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: typecheck/should_compile/T10390
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


In the following code, GHC will not compile unless the constraints on the higher-rank function have the same *order* as the method declaration in ApPair.

{-# LANGUAGE RankNTypes #-}

class ApPair r where
  apPair :: 
    (forall a . (ApPair a, Num a) => Maybe a)
    -> Maybe r 

instance (ApPair a, ApPair b) 
 => ApPair (a,b) where
  apPair = apPair'

apPair' :: (ApPair b, ApPair c)
  => (forall a . (ApPair a, Num a) => Maybe a) -> Maybe (b,c) 
apPair' f = 
  let (Just a) = apPair f
      (Just b) = apPair f
  in Just $ (a, b)

That is, the following does *not* compile:

apPair' :: (ApPair b, ApPair c)
  => (forall a . (Num a, ApPair a) => Maybe a) -> Maybe (b,c) 
apPair' f = 
  let (Just a) = apPair f
      (Just b) = apPair f
  in Just $ (a, b)

GHC probably shouldn't care about lexical matching when checking constraints.

Change History (2)

comment:1 Changed 5 years ago by Simon Peyton Jones <simonpj@…>

In c3e6b3ac50e7cc061825d49d06fb4fc81e6d5bc1/ghc:

Regression test for Trac #10390

comment:2 Changed 4 years ago by thomie

Milestone: 7.10.3
Resolution: fixed
Status: newclosed
Test Case: typecheck/should_compile/T10390

Already fixed. Milestone should really be 7.10.1 or 7.10.2.

Note: See TracTickets for help on using tickets.