Questions tagged [template-haskell]

Template Haskell is a GHC extension to Haskell that adds compile-time meta-programming facilities. This allows users to write programs that generate or modify their program at compile time: a form of compile-time macros.

You can learn more about it here:

375 questions
1
vote
1 answer

Why does Template Haskell add unexpected parens?

I have the following: import Control.Applicative import Control.Monad import Language.Haskell.TH mkExp :: [Name] -> ExpQ mkExp (name:[]) = [| ZipList $(varE name) |] mkExp (name:names) = [| ZipList $(varE name) <*> $(mkExp names) |] zipN :: Int…
Patrick Collins
  • 10,306
  • 5
  • 30
  • 69
1
vote
1 answer

Missing imports from Hamlet libraries

This is the code snippet from O reilly - Yesod - Widgets, getRootR = defaultLayout $ do setTitle "My Page Title" toWidget [lucius| h1 { color: green; } |] addScriptRemote…
user2879704
1
vote
1 answer

Obtaining TH.Name for '[] without -XTemplateHaskell

Is there a way to obtain (import from base modules or write expression) a value of type Language.Haskell.TH.Name that represents '[] without enabling -XTemplateHaskell? A good reason to do so is that tools like hlint do not play well with TH and…
Helmut Grohne
  • 6,578
  • 2
  • 31
  • 67
1
vote
1 answer

Automatically declaration yesod handlers using Template Haskell

For example, I have next entity type in Model User json username Text and following Haskell types: Entity User Delete handler for User: Routes file: /users/#UserId UserR DELETE Handler declaration: deleteUserR :: UserId -> Handler…
Bet
  • 389
  • 4
  • 13
1
vote
1 answer

Use Template Haskell to generate instance recursively

In GenericPretty, there is an Out class with a default implementation by using GHC.Generic magic. As you can see that I defined Person data type, and if I want to implement Out class I have to write 3 times manually since Person used Address and…
Song Zhang
  • 315
  • 1
  • 5
1
vote
1 answer

Can template-haskell be used to generate quasi-quotes?

A project that I'm currently working on makes extensive use of persistent. Instead of persistent's quasi-quoted syntax to specify models, I would like to use json. Right now, I use a script to generate the quasiquote which persistent expects using…
Vamshi Surabhi
  • 437
  • 4
  • 15
1
vote
0 answers

Why Template Haskell uses AST

I've been playing a bit with TemplateHaskell and I came across this problem, which is basically you can't do keyword name = [d| data $(name) = $(name) |] You have to do something like keyword name = return [DataD [] name [] [NormalC name []] []]…
mb14
  • 22,276
  • 7
  • 60
  • 102
1
vote
1 answer

Ignoring/Overriding an Instance generated using TemplateHaskell

I'm using Aeson for some client-server stuff that I'm doing, encoding ADTs as Json. I'm using Data.Aeson.TH to generate the toJSON instances I need, but the instances generated for Map types are really ugly and awful to deal with. I've defined my…
jmite
  • 8,171
  • 6
  • 40
  • 81
1
vote
1 answer

Parsing error when using single-quote 'Name convention in Template Haskell

I've copied the Aeson Template-Haskell module into a project of mine, and I'm trying to get it to compile. However, when I compile, I get the following error: compiler/Elm/Haskelm/Json.hs:283:1: parse error (possibly incorrect indentation or…
jmite
  • 8,171
  • 6
  • 40
  • 81
1
vote
2 answers

How to write pattern splices in expression quotation?

I'm trying to write a declaration using expression quotation, and whatever I try the compiler fails on pattern with a message like the following: Parse error in pattern: $pattern Here's an example: {-# LANGUAGE TemplateHaskell, QuasiQuotes…
Nikita Volkov
  • 42,792
  • 11
  • 94
  • 169
1
vote
1 answer

Can a quasiquoter 'use' variables defined in the same file it is called?

So, I'm starting to experiment with quasiquotation and template haskell. I want to modify an existing (large) quasiquotation code, while using the actual value of a variable defined where it is 'called'. To illustrate with a simple…
jcristovao
  • 554
  • 2
  • 12
1
vote
1 answer

Why are declaration splices not permitted inside delcaration brackets? Is there a workaround?

I'm trying to make a quasiquoter that defines some simple sugar for type declarations. The easiest way to do this is to just use some regular expressions to modify the input text string. But when I compile this code outline code: {-# LANGUAGE…
Mike Izbicki
  • 6,286
  • 1
  • 23
  • 53
1
vote
1 answer

Bind monadic variables over several functions

I'm interested in getting as close as possible to the following syntax. TH is just fine by me. bootapplication :: IO () bootapplication = do clientA <- newChan :: IO (Chan AMsg) clientB <- newChan :: IO (Chan BMsg) ... …
Evan
  • 381
  • 1
  • 12
1
vote
1 answer

Why does GHC not terminate with this GADT template Haskell module?

I have a problem with generating GADTs with template Haskell. The problem is that I can't get the code to compile completely. GHCI does not terminate when loading the file and a ghc process uses much memory and cpu as it can get (2.4GB, 50~70%). I…
Tim
  • 221
  • 3
  • 12
1
vote
1 answer

Data Type Haskell error

I declare some data type as follow: data TX_OR_TY = TX | TY data TX = X Int data TY = Y Float Now I write some function return their data type: funcTX :: TX funcTX = X 3 funcTY :: TY funcTY = Y 5 ordFuncTX :: TX -> Int -> Bool ordFuncTX (X a) b…
chipbk10
  • 5,783
  • 12
  • 49
  • 85