Opened 7 years ago

Closed 7 years ago

#6035 closed bug (fixed)

Kind-indexed type family failure with polymorphic kinds

Reported by: goldfire Owned by:
Priority: normal Milestone:
Component: Compiler (Type checker) Version: 7.5
Keywords: PolyKinds TypeFamilies Cc: pho@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: polykinds/T6035
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


The following code fails to compile:

{-# LANGUAGE PolyKinds, DataKinds, TypeFamilies, KindSignatures, GADTs, TypeOperators

data Nat = Zero | Succ Nat

type family Sing (a :: k) :: k -> *

data SNat n where
  SZero :: SNat Zero
  SSucc :: SNat n -> SNat (Succ n)

data SList (a :: [k]) where
  SNil :: SList '[]
  SCons :: Sing h h -> SList t -> SList (h ': t)

type instance Sing (a :: Nat) = SNat
type instance Sing (a :: [k]) = SList

term :: SList '[ '[Zero], '[]]
term = SCons (SCons SZero SNil) (SCons SNil SNil)

The error generated is

    Couldn't match type `Sing [Nat] ((':) Nat 'Zero ('[] Nat))'
                  with `SList Nat'
    Expected type: Sing
                     [Nat] ((':) Nat 'Zero ('[] Nat)) ((':) Nat 'Zero ('[] Nat))
      Actual type: SList Nat ((':) Nat 'Zero ('[] Nat))
    In the return type of a call of `SCons'
    In the first argument of `SCons', namely `(SCons SZero SNil)'
    In the expression: SCons (SCons SZero SNil) (SCons SNil SNil)

    Couldn't match type `Sing [Nat] ('[] Nat)' with `SList Nat'
    Expected type: Sing [Nat] ('[] Nat) ('[] Nat)
      Actual type: SList Nat ('[] Nat)
    In the first argument of `SCons', namely `SNil'
    In the second argument of `SCons', namely `(SCons SNil SNil)'
    In the expression: SCons (SCons SZero SNil) (SCons SNil SNil)

It seems that the Sing kind-indexed type family isn't quite working. My guess is that the problem is that we really want, say, Sing '[Zero] to be SList Nat, where Nat is the implicit kind parameter to SList. But, we can't say that. I would hope that the explicit kind annotation on the result of Sing would fix the implicit kind parameter to SList, but it doesn't seem to.

This was tested on 7.5.20120420.

Change History (3)

comment:1 Changed 7 years ago by PHO

Cc: pho@… added

comment:2 Changed 7 years ago by simonpj@…

commit 2316a90da6e78349874a181baa762ef60c80333e

Author: Simon Peyton Jones <>
Date:   Wed Apr 25 12:56:44 2012 +0100

    More fixes to kind polymorphism, fixes Trac #6035, #6036
    * Significant refactoring in tcFamPats and tcConDecl
    * It seems that we have to allow KindVars (not just
      TcKindVars during kind unification.  See
      Note [Unifying kind variables] in TcUnify.
    * Be consistent about zonkQuantifiedTyVars
    * Split the TcType->TcType zonker (in TcMType)
       from the TcType->Type   zonker (in TcHsSyn)
      The clever parameterisation was doing my head in,
      and it's only a small function
    * Remove some dead code (tcTyVarBndrsGen)

 compiler/ghci/RtClosureInspect.hs   |    4 +-
 compiler/typecheck/FamInst.lhs      |   11 ++--
 compiler/typecheck/TcHsSyn.lhs      |   90 ++++++++++++++++-----------
 compiler/typecheck/TcHsType.lhs     |   65 ++++++++-----------
 compiler/typecheck/TcMType.lhs      |   79 ++++++++---------------
 compiler/typecheck/TcTyClsDecls.lhs |  120 +++++++++++++++++++---------------
 compiler/typecheck/TcUnify.lhs      |   67 +++++++++++---------
 7 files changed, 221 insertions(+), 215 deletions(-)

comment:3 Changed 7 years ago by simonpj

difficulty: Unknown
Resolution: fixed
Status: newclosed
Test Case: polykinds/T6035
Note: See TracTickets for help on using tickets.