Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#10428 closed bug (duplicate)

GHC cannot match representations using Coercible constraint

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

Description

The following code compiles in 7.8.4 but fails in 7.10.1:

import Data.Coerce
coerceNewtype :: (Coercible (o r) (n m' r)) => [o r] -> [n m' r]
coerceNewtype = coerce

with the error

Couldn't match representation of type ‘n m' r’ with that of ‘o r’
arising from trying to show that the representations of
  ‘[o r]’ and
  ‘[n m' r]’ are the same
Relevant role signatures: type role [] representational

However, the following compiles:

{-# LANGUAGE TypeFamilies #-}

import Data.Coerce
coerceNewtype :: (Coercible a b, a ~ (o r), b ~ (n m' r)) => [o r] -> [n m' r]
coerceNewtype = coerce

Change History (8)

comment:1 Changed 3 years ago by goldfire

Owner: set to goldfire

Hmpf. I'm not terribly surprised that this would happen, but we should be able to nab such an easy case. Will take a look. But not this week.

comment:2 Changed 3 years ago by simonpj

Curious. With HEAD I get

T10428.hs:5:18: error:
    Couldn't match representation of type ‘o r’ with that of ‘n m' r’
    Inaccessible code in
      the type signature for:
      coerceNewtype :: Coercible (o r) (n m' r) => [o r] -> [n m' r]
    In the ambiguity check for the type signature for ‘coerceNewtype’:
      coerceNewtype :: forall (o :: * -> *) r (n :: * -> * -> *) m'.
                       Coercible (o r) (n m' r) =>
                       [o r] -> [n m' r]
    To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
    In the type signature for ‘coerceNewtype’:
      coerceNewtype :: (Coercible (o r) (n m' r)) => [o r] -> [n m' r]

comment:3 Changed 3 years ago by goldfire

comment:2 really shouldn't happen. That one surprises me.

comment:4 Changed 2 years ago by goldfire

Resolution: duplicate
Status: newclosed
Test Case: typecheck/should_compile/T10428

Turned out this is a duplicate of #10494, discovered separately. Fix on the way.

comment:5 Changed 2 years ago by Richard Eisenberg <eir@…>

comment:6 Changed 2 years ago by George

There was a question in email as to whether or not the fix is in 7.10.2. I just tried on 7.10.2 and get the same error so it seems it is not in 7.10.2

comment:7 Changed 2 years ago by crockeea

Milestone: 7.10.3

comment:8 Changed 2 years ago by bgamari

Milestone: 7.10.38.0.1

Sadly this won't be fixed in 7.10.3 either on account of the fix depending upon a rather large patch that would be quite tricky to backport (see #10494).

Note: See TracTickets for help on using tickets.