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

Using State.modify from another function

It is only a skeleton of program. I have main function, that State [Dec] [Dec] mainCon = do acc <- get put [] modify $ (++) [some func] return acc On one stage I call function: foldlWithKey' (\list' key' val' -> …
Ivan
  • 85
  • 6
0
votes
1 answer

How can I create Data by Template Haskell

Can i create data haskell with a help of Template Haskell. Data like : data Shape = Circle [Float] Double Int I want write a program, which create Data and then use it
Ivan
  • 85
  • 6
0
votes
1 answer

Language.Haskell.Exts.Syntax.Module to Template Haskell data structure

I've got a Module (Language.Haskell.Exts.Syntax.Module) and want to turn it into a template haskell data structure. How can I go about it? My first confusion is that the Module type from Language.Haskell.TH.Syntax doesn't look like a representation…
rem
  • 893
  • 4
  • 18
0
votes
1 answer

Template Haskell Function for Record Accessor Inheritance

I have two datatypes, A and B, which I have defined as: data A = A { aFoo :: Int, aBar :: String } data B = B { bFoo :: Int, bBar :: String, bBaz :: Float } I now need to create a heterogeneous list of As and Bs, so I define a sum type, C, as: data…
Kwarrtz
  • 2,693
  • 15
  • 24
0
votes
0 answers

error define a template haskell function

I am beginning to learn Template haskell, so I want create a function that receive a String param that define the name to the function to generate build_p5 :: String -> [Dec] build_p5 name = [ FunD p1 [ Clause [TupP [VarP a,VarP b]]…
oriaj
  • 768
  • 1
  • 16
  • 33
0
votes
1 answer

Dynamically add routes at compile time in Scotty

Is it possible to add routes dynamically at compile time through a config file by using Template Haskell or any other way. Scotty has a function addRoute but I want to use it dynamically. Example import qualified Data.Text.Lazy as LTB sampleRoutes…
user2512324
  • 791
  • 1
  • 6
  • 21
0
votes
1 answer

Template Haskell: Stage Error

I'm trying to understand how the Quasi Quoter generates TH structures. So I'm trying to convert the first example from Template Meta-programming for Haskell, from a quoted format to just the types. gen :: [Format] -> ExpQ -> ExpQ gen [] x =…
0
votes
1 answer

PersistMap in Yesod?

I'm using Yesod to design a website, and I'd like to use the PersistMap data type to map entries to text names. However, I can't seem to find any examples of how to declare a PersistMap field in the config/models file. When I try entryName [Text]…
jmite
  • 8,171
  • 6
  • 40
  • 81
0
votes
1 answer

What does this function do , Haskell

I need an algorithm that converts bin to dec I found the following code in the Internet , but I just do not know , what some variables mean: bin2dec :: [Int] -> Int bin2dec n = foldl (\a x->2*a+x) 0 n I already know foldl But what means (\a…
Blnpwr
  • 1,793
  • 4
  • 22
  • 43
0
votes
1 answer

Yesod Resources and URL type safety automation

I've been on a mission to learn everything about Yesod, and I'm (somewhat) stuck on the routing system and it's relation to subsites and cross-route linking in general. The first thing I would like to address is the "ResourceR" pattern found…
Athan Clark
  • 3,886
  • 2
  • 21
  • 39
0
votes
1 answer

How to elude renaming of symbols in AST generated from expression quotation?

You can see in this simple example how it renames the type and value constructors from A to A_0 and A_1 while converting from expression quotation to AST: Prelude Language.Haskell.TH> runQ [d|data A = A|] [DataD [] A_0 [] [NormalC A_1 []] []] How…
Nikita Volkov
  • 42,792
  • 11
  • 94
  • 169
0
votes
1 answer

Haskell type expression

I have two questions about Haskell type expression: Question 1 - I would like to declare a type NODE data NODE = Node String ATTR and a type ATTR contains 3 sub-type as follow: Source Bool Target Bool Ghost Int data ATTR = Source Bool | Target…
chipbk10
  • 5,783
  • 12
  • 49
  • 85
0
votes
1 answer

Directed Graph in Haskell

I am now struggling with Haskell. Even, I have some experience with imperative languages, with OOP, but Haskell seems to be different from them. I under-evaluated Haskell, and think learning a new language is not a problem with me. However, after…
chipbk10
  • 5,783
  • 12
  • 49
  • 85
-1
votes
1 answer

Haskell. Implement a function that takes a string as input and expands its compressed representation

Implement a function (myData2Fun) that takes a string as input and expands its compressed representation according to the rules for encoding series lengths. The essence of compression is that consecutive identical characters are combined into one…
-2
votes
1 answer

give (without duplicates) the names of actors who have co-starred in at least one film with a particular actor

I'm writing a movie database with Haskell. Like the title says, I am trying to give (without duplicates) the names of actors who have co-starred in at least one film with a particular actor. Here's my code until now: import Text.Printf import…
1 2 3
24
25