Skip to content

Type synonym using -XTypeInType can't be spliced with TH

The following code compiles:

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeInType #-}
{-# OPTIONS_GHC -ddump-splices #-}
module Foo where

import Data.Kind

type TySyn (k :: *) (a :: k) = ()

-- $([d| type TySyn2 (k :: *) (a :: k) = () |])

But uncomment the last line, and it doesn't compile:

$ /opt/ghc/head/bin/ghc Foo.hs 
[1 of 1] Compiling Foo              ( Foo.hs, Foo.o )
Foo.hs:10:3-43: Splicing declarations
    [d| type TySyn2_aBH (k_aBI :: *) (a_aBJ :: k_aBI) = () |]
  ======>
    type TySyn2_a4BF (k_a4BG :: Type) (a_a4BH :: k_a4BG) = ()

Foo.hs:10:3: error:
    • Couldn't match expected kind ‘GHC.Prim.Any’ with actual kind ‘k1’
    • In the type declaration for ‘TySyn2’

Foo.hs:10:3: error:
    • Kind variable ‘k_a4BG’ is implicitly bound in datatype
      ‘TySyn2’, but does not appear as the kind of any
      of its type variables. Perhaps you meant
      to bind it (with TypeInType) explicitly somewhere?
      Type variables with inferred kinds: k_a4BG (a_a4BH :: GHC.Prim.Any)
    • In the type declaration for ‘TySyn2’

There are two issues here:

  1. The error message claims that TySyn2 is a datatype when it is actually a type synonym. This should be easy enough to fix; just change the code that throws the error message to invoke tyConFlavour.
  2. For some reason, the type variable a in TySyn2 fails to kind-check. Somehow, an Any got in there, but I'm not sure where it snuck in.
Trac metadata
Trac field Value
Version 8.0.1-rc1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Template Haskell
Test case
Differential revisions
BlockedBy
Related
Blocking
CC goldfire
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information