Opened 7 years ago

Closed 4 years ago

#4128 closed feature request (fixed)

Can't capture classes inside a template haskell type quotation

Reported by: lilac Owned by:
Priority: low Milestone: 7.6.2
Component: Template Haskell Version: 6.12.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: th/T4128
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

GHC rejects the following:

{-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.TH
class C a where
data X = X
fmap return $ instanceD (cxt []) [t| C $(conT ''X) |] []

with the error:

test.hs:5:23:
    Class `C' used as a type
    In the Template Haskell quotation [t| C $(conT 'X) |]
    In the second argument of `instanceD', namely `[t| C $(conT 'X) |]'
    In the expression: instanceD (cxt []) [t| C $(conT 'X) |] []

This is frustrating, since that quotation would have resulted in exactly the TH AST fragment I wanted, had the error not occurred. Instead I must resort to:

instanceD (cxt []) (appT (conT ''Storable) (conT ''X)) []

Incidentally, the error message produced is wrong: The error says 'X whereas I wrote X.

Change History (10)

comment:1 Changed 7 years ago by igloo

Milestone: 6.14.1

comment:2 Changed 7 years ago by simonpj

Blocking: 4230 added

This too related to the global discussion in #4230. If we did less kind-checking of the type quote, we wouldn't reject the quote.

comment:3 Changed 7 years ago by simonpj

Blocked By: 4230 added
Blocking: 4230 removed

comment:4 Changed 7 years ago by igloo

Milestone: 7.0.17.0.2

comment:5 Changed 6 years ago by igloo

Milestone: 7.0.27.2.1

comment:6 Changed 6 years ago by igloo

Milestone: 7.2.17.4.1

comment:7 Changed 5 years ago by igloo

Milestone: 7.4.17.6.1
Priority: normallow

comment:8 Changed 5 years ago by igloo

Milestone: 7.6.17.6.2

comment:9 Changed 4 years ago by Krzysztof Gogolewski <krz.gogolewski@…>

In e595c81ee0951f17d34b918123dfa7711710fe89/testsuite:

Add tests for new TH #4124, #4128, #4170, #4364, #6062

comment:10 Changed 4 years ago by monoidal

Blocked By: 4230 removed
difficulty: Unknown
Resolution: fixed
Status: newclosed
Test Case: th/T4128

This test was already working as of GHC 7.6; I think this was fixed by addition of -XConstraintKinds.

Note: See TracTickets for help on using tickets.