Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,383
    • Issues 4,383
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 373
    • Merge Requests 373
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #19301

Closed
Open
Opened Feb 02, 2021 by Sylvain Henry@hsyl20Developer

TH: quote both an imported name and its computed value

This is a follow-up of the discussion on haskell-cafe: https://mail.haskell.org/pipermail/haskell-cafe/2021-February/133368.html

I have the following kind of template haskell code:

module Bar where
bar :: String
bar = "whatever"

module Foo where
foo :: String -> Name -> Q [Dec]
foo str name = ...

module FooBar where
import Foo
import Bar
foo bar 'bar

It works great as in foo I can use both bar's Name and bar's value computed at compile time.

But it's unsafe for my purpose because a user could call foo "fakeBarValue" 'bar.

I would like a way to quote both the name and the value of an import into an unforgeable value (by the user, TH can obviously):

module TH.Internal
  ( Named -- constructor not exported
  , namedThing
  , namedName
  )
where
data Named a = Named { namedThing :: a, namedName :: Name }

module Foo where
foo :: Named String -> Q [Dec]
foo n = ...

module FooBar where
import Foo
import Bar
foo '''bar -- new kind of quote?

Or perhaps an alternative way would be to lift the stage restriction ("‘name’ is used in a top-level splice, quasi-quote, or annotation, and must be imported, not defined locally") for imported names? It would allow:

module Foo (foo) where
foo :: ImportedName -> Q [Dec]
foo name = ... $(varE name)...

module FooBar where
import Foo
import Bar
foo 'bar
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#19301