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

Can I Use Template Haskell to Generate Hamlet Code?

I have come across an interesting problem that I thought might be a pertinent place for Template Haskell. I'm working on a web front-end to a database using yesod and yesod-persistant. I am generating my database types using mkPerist function and…
Brooks
  • 359
  • 3
  • 9
1
vote
1 answer

How we can use type level string in template haskell?

I played around with symbolVal and template haskell as follows on ghci. >>> :set -XTemplateHaskell -XQuasiQuotes -XDataKinds >>> import Language.Haskell.TH >>> import Data.Proxy >>> import GHC.TypeLits >>> $([| symbolVal (Proxy :: Proxy "foo") |])…
1
vote
0 answers

Automatically derive Unbox for newtype without TH

So I've got a pretty basic newtype: newtype SomeID = SomeID Word64 deriving (Show,Eq) And I would like to use this type in an unboxed vector, but on first inspection this seems to be more complicated than deriving...say...Storable. And when I say…
carpemb
  • 691
  • 1
  • 8
  • 19
1
vote
1 answer

How to fix QuasiQuoter warning?

I'm using the simple quasiquoter from the Haskell Wiki for multiline strings. import Language.Haskell.TH import Language.Haskell.TH.Quote str = QuasiQuoter { quoteExp = stringE } I get the following warning: Fields of ‘QuasiQuoter’ not…
Steven Shaw
  • 6,063
  • 3
  • 33
  • 44
1
vote
1 answer

Preprocessor in Haskell

I want to generate import qualified Aaaa.Bbb.Ccc as Ccc automatically at compile time. Is there any way to do that? Maybe by Template Haskell or anyhow else with any extention? I think it's similar to macroses in C and the function $(...) in…
Incerteza
  • 32,326
  • 47
  • 154
  • 261
1
vote
2 answers

Need to generate possible trees from list

I want to generate all possible trees from an int list [Int] -> [T] but I generate only one tree. 1 1 2 2 3 5 4 14 5 42 like these Catalan numbers. If my list size is 3, I want to generate 5 possible…
samcuk
  • 21
  • 4
1
vote
1 answer

Can I convert template haskell to .hs?

I created Data with a help of Template Haskell. I use it from another program by $(code here). So, can I convert Data to .hs file? I want to see the structure of Data.
OMars
  • 13
  • 3
1
vote
1 answer

Convert to typed value from String

I have file with list of values and types, after reading them I need to put them into db. For that, I need to supply insertion function with properly typed tuple, so I'm trying to convert values with something like this toProperType :: String ->…
Filip van Hoft
  • 301
  • 1
  • 7
1
vote
0 answers

Type synonyms with TemplateHaskell

If I have a type data Foo = Foo Int Int where frequently (but not always) the second parameter is a (fixed) function of the first, I could write a helper function mkFoo m = Foo m (f m) to reduce duplication. I have this exact problem, but at the…
crockeea
  • 21,651
  • 10
  • 48
  • 101
1
vote
1 answer

GHCi interactive linking error during happstack-server installation

I’m trying to build a project in a cabal sandbox that depends on happstack-server, but this package fails to build. Here is the content of .cabal-sandbox/logs/happstack-server-7.4.6.1.log: Building happstack-server-7.4.6.1... Preprocessing library…
WilQu
  • 7,131
  • 6
  • 30
  • 38
1
vote
1 answer

Creating libraries from machine readable specifications in Haskell

I have a specification and I wish to transform it into a library. I can write a program that writes out Haskel source. However is there a cleaner way that would allow me to compile the specification directly (perhaps using templates)? References to…
Q the Platypus
  • 825
  • 1
  • 7
  • 13
1
vote
1 answer

Template haskell type list

Is there a way to construct type level lists using '[Foo, Bar, Maybe Quux] syntax? It's possible to do: promotedTypeList :: [Q Type] -> Q Type promotedTypeList [] = promotedNilT promotedTypeList (t:ts) = [t| $promotedConsT $t $(promotedTypeList…
phadej
  • 11,947
  • 41
  • 78
1
vote
1 answer

Retrieving annotations from the same module

Suppose I define my own annotation type: {-# LANGUAGE DeriveDataTypeable #-} module Def where import Data.Data data MyAnn = MyAnn Int deriving (Show, Typeable, Data) and some Template Haskell function to access it: module TH where import…
Cactus
  • 27,075
  • 9
  • 69
  • 149
1
vote
1 answer

Haskell inline-c multi-step build/link with Cabal

I am writing an FFI-heavy library that uses inline-c, and the build process is: run GHC on the inline-c files, produce C compile C produced in previous step into dynamic libraries compile Haskell interface while linking both the object files…
ocramz
  • 816
  • 6
  • 18
1
vote
1 answer

How does one "run" a data declaration from a quasiquoter

I'm trying to write a quasiquoter for some type declarations. I've written something along the lines of {-# LANGUAGE TemplateHaskell #-} import Language.Haskell.TH as TH import Language.Haskell.TH.Quote sample :: QuasiQuoter sample = let tName …
Khanzor
  • 4,830
  • 3
  • 25
  • 41