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

Avoiding boilerplate that's not part of a Haskell class

I'm developing a framework for artificial life experiments. The framework can support multiple species, as long as each species is an instance of the Agent class. I wrap each Agent in an AgentBox so that I can read, write, and use them without…
mhwombat
  • 8,026
  • 28
  • 53
1
vote
1 answer

Template Haskell tuple update function

Is there a function, or how do I write a function updateTuple, such that: $(updateTuple 5 (0, 2, 4)) (_ -> 'a', (*2), _ -> 42) (1, 2, 3, 'b', 'c') -> ('a', 2, 6, 'b', 42) Basically the first argument of updateTuple is the length of the tuple to…
Clinton
  • 22,361
  • 15
  • 67
  • 163
0
votes
1 answer

Implement a ReaderT monad Type for mocking network api calls

data TestEnv = TestEnv { rateLimiter' :: !TokenBucket , apiManager :: !Manager , apiKey :: !BS.ByteString } type BunnyReaderT m = ReaderT TestEnv m class MonadIO m => HasBunny m where runRequest :: Request -> m (Response BSL.ByteString) …
0
votes
1 answer

Obfuscating values of compile-time parameters in Haskell

In my Haskell application I implemented the following mechanism for passing sensitive information to the binary (without resorting to CLI parameters): I use a TemplateHaskell mechanism for reading environment variables at compile time: {-#…
Wojciech Gac
  • 1,538
  • 1
  • 16
  • 30
0
votes
1 answer

No Store instance for Aeson object

The code below generates orphan instances for store. It works fine for aeson 1.4.7.1 but generates error in aeson 2.0.3.0. {-# LANGUAGE DeriveDataTypeable,DeriveGeneric,TemplateHaskell,GeneralizedNewtypeDeriving, OverloadedStrings #-} {-#…
Sal
  • 4,312
  • 1
  • 17
  • 26
0
votes
1 answer

No instance for (Data.Vector.Generic.Base.Vector ...) when using Hasql.TH

I have a query I'm running in Hasql using Hasql.TH, and I'm encountering an error I've never seen before (see below). I'm seen this SO question/answer which references the version of vector, but (a) I'm using stack so these things should be resolved…
GTF
  • 8,031
  • 5
  • 36
  • 59
0
votes
1 answer

(Template?) Haskell get name of function at run or compile time

I have a list of imported functions as a top level binding. I want to get the name of each function in the list without hardcoding them. Because the list is known at compile time using Template Haskell it should be possible to get the names of every…
Fabus1184
  • 149
  • 7
0
votes
1 answer

How to migrate this Template Haskell Lift instance to version 2.18

I have a Lift instance that works with template-haskell 2.14, but won't compile with later versions. Can someone explain what changes are needed? {-# LANGUAGE FlexibleInstances, TemplateHaskell #-} module LiftBS where import Data.ByteString as B…
David Fox
  • 654
  • 4
  • 10
0
votes
1 answer

How to "encode" this simple expression in template Haskell?

I have a call myFun @m @d. And now I want to code it for my template Haskell. I try let myFunCall = AppTypeE (VarE $ mkName "myFun") (AppT (VarT $ mkName "m") (VarT $ mkName "d")) But it's invalid because I get myFun @(m d). To be honest I have not…
RandomB
  • 3,367
  • 19
  • 30
0
votes
0 answers

Save a set of functions to a file

I have a specific set of functions of type Function which I want to be able to store to and parse from disk. So I create a helper data type FunctionData like so data Function = Function {..., functionToFunctionData :: FunctionData} fFun :: Some ->…
Dominik Schrempf
  • 827
  • 8
  • 14
0
votes
1 answer

How reference a function from TemplateHaskell

I cannot figure out to call something from an expression generated with TemplateHaskell. Let's say I want to use ":" operator to cons list. I saw syntax '(:) but it is not working for me. Also I tried to lookupNameValue and wrap mkName ":" into…
Daniil Iaitskov
  • 5,525
  • 8
  • 39
  • 49
0
votes
1 answer

How to define all musical note names .. Cbb Cb C Cs Css .. as constructors in Haskell

I was playing with musical note names having the goal to not confuse enharmonic equals, i.e. I wanted to get the accidentals (sharps and flats) right. The note a perfect fifth above the note B needs to be Fs and not Gb, even though Fs and Gb are the…
Martin Drautzburg
  • 5,143
  • 1
  • 27
  • 39
0
votes
1 answer

Couldn't match expected type 'SomeEntity’ with actual type ‘Key SomeEntity’

Hi I am a beginner in Haskell and Yesod and I need help with this problem. These are my entities: Location name Text sqltype=varchar(255) address AddressId Maybe sqltype=varchar(255) UniqueLocationName name deriving Show…
jovanKg
  • 35
  • 7
0
votes
1 answer

Type not in scope, but the required library is being imported

I have to work with the following Template Haskell code: {-# OPTIONS_GHC -Wall #-} {-# LANGUAGE TemplateHaskell #-} module myModule where import Language.Haskell.TH newtype C a = C (TExpQ a) unC :: C a -> TExpQ a unC (C x) = x However when I…
pmichaels
  • 139
  • 6
0
votes
1 answer

Configurable path prefix with Yesod

I have the following web server: {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-} import Data.Text (Text) import Yesod data App =…
stevemao
  • 1,423
  • 1
  • 16
  • 29