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
2
votes
1 answer

Naked expression at top level for simple Template Haskell experimentation

I'm trying to get my head wrapped around Persistent, and one of the things I'm trying to learn is it's derivePersistField template haskell function. Now, I realize there's a stage restriction, forcing GHC to render the rest of the code that the…
Athan Clark
  • 3,886
  • 2
  • 21
  • 39
2
votes
1 answer

Existential quantifier silently disrupts Template Haskell (makeLenses). Why?

I have this file: {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE ExistentialQuantification #-} module Toy where import Control.Lens data Bar = Bar { _barish :: String } data Foo = forall a. Show a => Foo { _fooish :: a } $(makeLenses…
ajp
  • 1,723
  • 14
  • 22
2
votes
1 answer

How does one apply HamletSettings to a quasiquote in Hamlet?

Background: I am studying how Hamlet works, with WAI, but without Yesod. I have no grasp of Template Haskell, but before I dive into it, I am wondering if there is a known/quick solution for this task. Specifics: I would like to know how to change…
jerng
  • 499
  • 6
  • 13
2
votes
1 answer

Template Haskell compile error when calling with different parameters

Why does the following fail to compile (on GHC 7.4.2)? {-# LANGUAGE TemplateHaskell #-} f1 = $([| id |]) main = print $ (f1 (42 :: Int), f1 (42 :: Integer)) Note that the following compiles fine: {-# LANGUAGE TemplateHaskell #-} f1 = id -- Don't…
Clinton
  • 22,361
  • 15
  • 67
  • 163
2
votes
1 answer

Template Haskell compile error

Consider the following code: {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE NoMonomorphismRestriction #-} import Data.HList.GhcSyntax((.!.),(.=.),(.*.)) import Data.HList.Record(emptyRecord) import Data.HList.TypeCastGeneric1 import…
Clinton
  • 22,361
  • 15
  • 67
  • 163
1
vote
1 answer

How do I get all instances of HasField type class?

Asking ghci about instances of a record type R does not return the instances of HasField. data R = MkR {f1 :: Int, f2 :: Int} instance HasField "f3" R Int where getField (MkR a b) = a + b -- ghci >:i R type R :: * data R = MkR {f1 :: Int, f2 ::…
lsmor
  • 4,698
  • 17
  • 38
1
vote
1 answer

Names with single quotes in Template Haskell

Normally, when using Template Haskell, names of bindings and data constructors are quoted by prefixing them with a single quote: showName, justName :: Name showName = 'show justName = 'Just Unfortunately, this doesn't work for names whose second…
dfeuer
  • 48,079
  • 5
  • 63
  • 167
1
vote
1 answer

DuplicateRecordFields causes Template Haskell 'Illegal variable name' error

I do not understand why the DuplicateRecordFields language pragma is causing a compile time error in a template haskell splice. Example: -- TypeModule.hs {-# LANGUAGE DuplicateRecordFields #-} module TypeModule where data A = A {foo :: Int}…
1
vote
1 answer

Template Haskell resolve type aliases

I'm using template Haskell to generate data about a type. For many reasons I need the type to be used to be "normalized". So it shouldn't be a type alias/synonym. I really don't want to disallow using type aliases in the construct since some types…
user2882307
1
vote
1 answer

How to compile QuasiQuoter during runtime?

I have a 'QuasiQuoter' which is useful in source code in Haskell, but also as a standalone application. So, I need to be able to run QuasiQuoter During the compile time in Haskell - [myGrammar|someCommand|] In runtime (runtime compilation) in shell…
Přemysl Šťastný
  • 1,676
  • 2
  • 18
  • 39
1
vote
1 answer

Listing all fixity declarations in Quasiquote monad

I would like to list all fixity declarations in Quasiquote monad so I am able to pass all the infix operators from Haskell grammar to my Quasiquote grammar. Is there any method in template-haskell which allows me to do so please? I can't find…
Přemysl Šťastný
  • 1,676
  • 2
  • 18
  • 39
1
vote
0 answers

Inferred type synonym with a polymorphic typed Template Haskell definition contains GHC.Types.Any

I'm writing some typed template Haskell code on GHC 8.10.4 . For example, the following definition gets a sane type : fmapQ f xs = [|| fmap $$(f) $$(xs) ||] but if I introduce a synonym to be used inline : (>$<) = fmapQ this typechecks as (>$<) ::…
1
vote
1 answer

Haskell ignore unresolved imports

Very specific use case: I'm building an autotester system, where students submit their assignments, which is automarked. However, VSCode will often insert bogus imports, which cannot get resolved on the testing machine. However, those modules are…
Lorenzo
  • 2,160
  • 12
  • 29
1
vote
1 answer

Generating newtype wrappers with helpers using Template Haskell

I have a really simple use-case where I have a basic type but for the purposes of my various record types in my data model, I want each record to have wrapped version of this type: type UID = Integer -- specialised version newtype MyRecordID =…
GTF
  • 8,031
  • 5
  • 36
  • 59
1
vote
1 answer

Spread Haskell Singleton definition among modules

I’m using the singletons and singletons-th libraries, and I want (if possible) to split a singleton definition between files. I tried creating a data family, but I’m getting a Declaration cannot be promoted error. data family Field data family…
David Davó
  • 417
  • 1
  • 4
  • 18