Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,859
    • Issues 4,859
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 453
    • Merge requests 453
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #15298
Closed
Open
Created Jun 21, 2018 by Nathan Collins@ntc2

Support spliced function names in type signatures in TH declaration quotes

There doesn't seem to be a way to splice function names into type signatures in Template Haskell declaration quotes [d|...|]. For example, fDecl1 below does not work.

According to this StackOverflow answer, the approach in fDecl2 below used to work, but it doesn't work with recent GHCs and is much less readable than fDecl1.

{-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.TH

fName :: Name
fName = mkName "f"

fTy :: TypeQ
fTy = [t| Int |]

fBody :: ExpQ
fBody = [e| 3 |]

-- | Not allowed:
--
-- @
-- error:
--    Invalid type signature: $fName :: ...
--    Should be of form <variable> :: <type>
-- @
--
-- Similarly, using @$(varP fName) :: $fTy@ fails with an analogous
-- error.
fDecl1 :: DecsQ
fDecl1 = [d| $fName        :: $fTy
             $(varP fName) = $fBody |]

-- | Not allowed:
--
-- @
-- error:
--     Splices within declaration brackets not (yet) handled by Template Haskell
-- @
fDecl2 :: DecsQ
fDecl2 = [d| $((:[]) <$> sigD fName fTy)
             $(varP fName) = $fBody |]
Trac metadata
Trac field Value
Version 8.4.3
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related #11129 (closed)
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking