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.
template-haskell
381
questions
2
votes
2
answers
56
views
Is there a way to get `cabal` to detect changes to non-Haskell source files?
I'm using template haskell to include content from non-Haskell files in some of my code, and this content is then parsed and used. The problem that I have with using cabal as a build tool for this is ...
2
votes
1
answer
43
views
How to get terms names of GADT in Template Haskell?
If I have GADT like:
data Pkt (m::Msg) (d::Dir) where
GetResourcesPkt :: Pkt 'ResourcesM 'Ask
MyResourcesPkt ...
1
vote
1
answer
64
views
TemplateHaskell's addDependentFile doesn't work when the file doesn't exist
I want my TemplateHaskell expression recompiled when the dependent file changes and in case it doesn't exist, use a fallback file. But once the dependent file is created I want to also recompile.
The ...
1
vote
1
answer
65
views
Printing an expression using Dump library fails
I would like to print the property being tested alongside the argument that caused failure. So, I am trying to solve the second part of the problem by using Debug.Dump from the dump package. This is a ...
1
vote
0
answers
122
views
How can I pinpoint the specific location where property tests fail when using QuickCheck more efficiently?
Current solution:
I am currently using counterexample function from Test.Quickcheck:
counterexample :: Testable prop => String -> prop -> Property
to add informative messages in order to ...
2
votes
0
answers
47
views
Can I attach Haddock comments to declarations in a `[d|���|]` declaration quote?
If I have a declaration quote passed to a Template Haskell function, something like
someTHFunction
[d|
-- | Some documentation
data SomeType = SomeConstructor | SomeOtherConstructor
|]
...
3
votes
0
answers
44
views
How to refer to a module (and construct the names of its contents) in template haskell
I have a splice I'm writing in TH which needs to take a list of module names and create new names based on a convention I have for these modules. At the moment I am doing this by passing in Strings of ...
2
votes
2
answers
75
views
How do I capture the named value created by this TH code
Here's my Template Haskell code
objectGIDDeclaration :: String -> Integer -> Q [Dec]
objectGIDDeclaration dnameSTR gid = pure fDec
where
dname = dnameSTR <> "GID"
fDec = [...
0
votes
1
answer
93
views
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
...
2
votes
1
answer
166
views
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
...
0
votes
1
answer
125
views
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 ...
0
votes
1
answer
56
views
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,...
3
votes
1
answer
88
views
How to force Stack to re-compile when a text file read using template haskell changes?
I'm currently writing a configuration for xmonad. I wanted to make a variable color theme config, so I made each color theme a type, eg data Dracula = Dracula, and a Color type class
class ColorTheme ...
0
votes
1
answer
49
views
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'...
0
votes
1
answer
257
views
(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 ...