Skip to content

No -Wbadly-staged-types warning for required type argument

File:

{-# LANGUAGE RequiredTypeArguments, TemplateHaskellQuotes #-}
module M where

import Language.Haskell.TH

idVis :: forall a -> a -> a
idVis _ x = x

f :: forall a -> Code Q (a -> a)
f a = [|| id @a ||]

g :: forall a -> Code Q (a -> a)
g a = [|| idVis a ||]

GHC warns about f (#23829 (closed))

M.hs:10:15: warning: [GHC-86357] [-Wbadly-staged-types]
    Badly staged type: a is bound at stage 1 but used at stage 2
   |
10 | f a = [|| id @a ||]
   |               ^

This warning is correct. Attempting to splice $$(f Int) doesn't work, as described in the manual.

However, there is no warning about g, even though it has the same problem.

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