Skip to content

Standalone kind signature with VDQ does not roundtrip through Template Haskell

I would expect the following program to compile:

{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -ddump-splices #-}
module Bug where

import Data.Kind

$([d| type T :: forall k -> k -> Type
      type family T :: forall k -> k -> Type
    |])

But it doesn't:

$ ~/Software/ghc/inplace/bin/ghc-stage2 Bug.hs
[1 of 1] Compiling Bug              ( Bug.hs, Bug.o, Bug.dyn_o )
Bug.hs:(11,3)-(13,6): Splicing declarations
    [d| type T_arW :: forall k_aWR -> k_aWR -> Type

        type family T_arW :: forall k_arX -> k_arX -> Type |]
  ======>
    type T_a4bz :: forall k_aWR. k_aWR -> Type
    type family T_a4bz :: forall k_a4bA -> k_a4bA -> Type

Bug.hs:11:3: error:
    • Couldn't match expected kind ‘forall k0 -> k0 -> *’
                  with actual kind ‘k -> *’
    • In the type family declaration for ‘T’
   |
11 | $([d| type T :: forall k -> k -> Type
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...

As the -ddump-splices output reveals, roundtripping through Template Haskell appears to have turned type T :: forall k -> k -> Type into forall k. k -> Type, which is a different thing altogether. Note that the forall k -> k -> Type in the explicit return kind of type family T is not affected.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information