Skip to content

Type families cause wrapper types to disappear without cause

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: http://www.haskell.org/ghc/  :? 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)
 
 <interactive>:8:15:
     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)
 
 <interactive>:10:15:
     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.

Trac metadata
Trac field Value
Version 7.8.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Type checker)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information