Opened 7 years ago

Closed 6 years ago

#7477 closed bug (fixed)

reifyInstances can't deal with polykinded type families

Reported by: goldfire Owned by:
Priority: normal Milestone: 7.8.1
Component: Compiler Version: 7.7
Keywords: TemplateHaskell TypeFamilies PolyKinds Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: th/T7477
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


When I run the following code

{-# LANGUAGE DataKinds, KindSignatures, PolyKinds, TypeFamilies, TemplateHaskell #-}

import Language.Haskell.TH

type family F (a :: k)
type instance F Int = Bool

$( do { info <- reifyInstances ''F [ConT ''Int]
      ; reportWarning (pprint info)
      ; return [] })

I get this error:

    Wrong number of types (expected 2)
    In the argument of reifyInstances: Main.F GHC.Types.Int

I assumed that TH wanted me to supply the kind parameter, so I tried this:

$( do { info <- reifyInstances ''F [StarT, ConT ''Int]

I got this response:

    `F' is applied to too many type arguments
    In the argument of reifyInstances: Main.F * GHC.Types.Int

I poked around in the code to see what might be causing it. I found a couple of interesting things:

  • reifyInstances uses tyConArity to get the arity of a type family. For my F, tyConArity reported 3. So, I wrote some code to go through the kind and count only non-superkind arguments. This didn't fix the problem, because ...
  • reifyInstances passes control off, through a handful of other functions, to matchExpectedFunKind, which works only with FunTy, not ForAllTy. So, my F, whose kind is headed by ForAllTy, looks like it takes no arguments at all.

I could try to fix this, but I'm worried about upsetting the apple cart here. If a knowledgeable individual could give some pointers about what's safe and what's not safe to change in this code, I'm happy to write the fix.

This was all tested on 7.7.20121130.

Change History (5)

comment:1 Changed 6 years ago by igloo

difficulty: Unknown
Milestone: 7.8.1

comment:2 Changed 6 years ago by monoidal

For what's worth, we now get an empty warning.

comment:3 Changed 6 years ago by Simon Peyton Jones <simonpj@…>

In 8944fd3fc5fa7d435f438c5680c8d177257d27e9/ghc:

Zonk the type in reifyInstances (fixes Trac #7477)

A simple oversight, but crucial!  tcLHsType was returning
    F k Int
where k is a unification variable that has been unified with *

comment:4 Changed 6 years ago by Simon Peyton Jones <simonpj@…>

comment:5 Changed 6 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: th/T7477

Fixed at last.


Note: See TracTickets for help on using tickets.