Opened 5 years ago

Closed 5 years ago

#10085 closed bug (invalid)

Type families cause wrapper types to disappear without cause

Reported by: tathougies Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 7.8.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


I tried to summarize the bug in the title, but I'm absolutely at a loss to understand what's going on here.

Here's the output of a GHCi session:

 GHCi, version 7.8.3:  :? for help
 Loading package ghc-prim ... linking ... done.
 Loading package integer-gmp ... linking ... done.
 Loading package base ... linking ... done.
 Prelude> :set -XTypeFamilies
 Prelude> type family Strange (f :: * -> *) ty where { Strange f ty = Maybe (f ty) }
 Prelude> newtype Identity a = Identity { runIdentity :: a }
 Prelude> newtype StrangeHolder f = StrangeHolder (f Int)
 Prelude> let x = Just (Identity 3) :: Strange Identity Int
 Prelude> :type x
 x :: Maybe (Identity Int)
 Prelude> StrangeHolder _ :: StrangeHolder (Strange Identity)
     Found hole _ with type: Maybe (Identity Int)
     Relevant bindings include
       it :: StrangeHolder (Strange Identity) (bound at <interactive>:8:1)
     In the first argument of StrangeHolder, namely _
     In the expression:
         StrangeHolder _ :: StrangeHolder (Strange Identity)
     In an equation for it:
         it = StrangeHolder _ :: StrangeHolder (Strange Identity)
 Prelude> :type x
 x :: Maybe (Identity Int)
 Prelude> StrangeHolder x :: StrangeHolder (Strange Identity)
     Couldn't match type Identity Int with Int
     Expected type: Maybe Int
       Actual type: Maybe (Identity Int)
     In the first argument of StrangeHolder, namely x
     In the expression:
         StrangeHolder x :: StrangeHolder (Strange Identity)

GHC reports that it is expecting the type Maybe (Identity Int) as the first argument to StrangeHolder. It also reports that x has type Maybe (Identity Int), but when I go to put x into a StrangeHolder, GHC has seemingly gotten rid of Identity, and now expects x to be of type Maybe Int. I think this is a bug, since the Identity type seems to disappear without cause.

Change History (2)

comment:1 Changed 5 years ago by glguy

There may be other issues here, but a significant one is that you're partially applying a type synonym family. This check was missing in 7.8 but is fixed for 7.10

comment:2 Changed 5 years ago by simonpj

Resolution: invalid
Status: newclosed

Yes, glguy is spot on: you cannot partially apply a type family. This was a bug in 7.8 and I have no idea what unpredictable consequences might occur if you do. If you can make your strange behaviour happen with 7.10 then let's look at it.

I'm sorry about the bug in 7.8 which has wasted some of your time. I'll close this as invalid (our fault not yours), but do re-open if you can make something like this happen without partial application.


Note: See TracTickets for help on using tickets.