Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7744463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:46:25+00:00 2026-06-01T09:46:25+00:00

Quasi-quotes allow generating AST code during compilations, but it inserts generated code at the

  • 0

Quasi-quotes allow generating AST code during compilations, but it inserts generated code at the place where Quasi-quote was written. Is it possible in any way to insert the compile-time generated code elsewhere? For example in specific module files which are different from the one where QQ was written? It would depend on hard-coded module structure, but that’s fine.

If that’s not possible with QQ but anyone knows a different way of achieving it, I am open for suggestions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:46:26+00:00Added an answer on June 1, 2026 at 9:46 am

    To answer this, it’s helpful to know what a quasi-quoter is. From the GHC Documentation, a quasi-quoter is a value of

    data QuasiQuoter = QuasiQuoter { quoteExp  :: String -> Q Exp,
                                     quotePat  :: String -> Q Pat,
                                     quoteType :: String -> Q Type,
                                     quoteDec  :: String -> Q [Dec] }
    

    That is, it’s a parser from an arbitrary String to one or more of ExpQ, PatQ, TypeQ, and DecQ, which are Template Haskell representations of expressions, patterns, types, and declarations respectively.

    When you use a quasi-quote, GHC applies the parser to the String to create a ExpQ (or other type), then splices in the resulting template haskell expression to produce an actual value.

    It sounds like what you’re asking to do is separate the quasiquote parsing and splicing, so that you have access to the TH expression. Then you can import that expression into another module and splice it there yourself.

    Knowing the type of a quasi-quoter, it’s readily apparent this is possible. Normally you use a QQ as

    -- file Expr.hs
    eval :: Expr -> Integer
    expr = QuasiQuoter { quoteExp = parseExprExp, quotePat =  parseExprPat }
    
    -- file Foo.hs
    import Expr
    myInt = eval [expr|1 + 2|]
    

    Instead, you can extract the parser yourself, get a TH expression, and splice it later:

    -- file Foo.hs
    import Expr
    
    -- run the QQ parser
    myInt_TH :: ExpQ
    myInt_TH = quoteExp expr "1 + 2"
    
    -- file Bar.hs
    import Foo.hs
    
    -- run the TH splice
    myInt = $(myInt_TH)
    

    Of course if you’re writing all this yourself, you can skip the quasi-quotes and use a parser and Template Haskell directly. It’s pretty much the same thing either way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having an issue generating scrambled quasi-monte carlo numbers in parfor loops. The
I tried your script but it isn't working right. I have edited my code
So, I'm getting a pretty strange error here... I tried to isolate it but
I know I can use a quasi-random number generation function/variable called Rnd. However, I've
I know this kind of question has been asked a few times, but alot
I have a number of quasi-related projects that I want to version control. In
This is a continuation of another question about efficiently getting quasi-random numbers. I need
I want to code a perl application that would crawl some websites and collect
I'd like to add section headers to my grouped table view's sections but I'd
I'm using quasi the module approach From a Table - Using Locals Internally as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.