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

What does `BytesPrimL` represent?

I can figure out what most literals represent with ppr, e.g. WordPrimL 7 = 7##, CharPrimL 'x' = 'x'#, etc. The only constructor I can't figure out is BytesPrimL: λ> bytes <- mallocForeignPtrArray @Word8 5 λ> let bytesLit = LitE (BytesPrimL (mkBytes…
fluffyyboii
  • 635
  • 6
  • 15
2
votes
1 answer

Why can't I cabal install template-haskell-2.17.0.0?

I am trying to install the specific version template-haskell-2.17.0.0. I run this command, but get an error during dependency resolution: ❯ cabal install template-haskell-2.17.0.0 --lib Resolving dependencies... cabal: Could not resolve…
2
votes
0 answers

Is there a way to derive Lift for "IO a" in Haskell?

For awhile now, whenever people mention the performance hit of free monad + interpreter pattern, I've had this vague idea in my head that: "Why not just use Template Haskell to evaluate your interpreter at compile time? Thus negating the performance…
Nathan BeDell
  • 2,263
  • 1
  • 14
  • 25
2
votes
1 answer

Plutus Interpreter Error in Plutus Playground

This code compiles but when I click on Evaluate I get this error. I'm not sure if this is from the playground or not because I used the same code from their new tutorial . The error doesn't show up when I compile it only happens when I attempt view…
jnprogrammer
  • 153
  • 1
  • 3
  • 9
2
votes
0 answers

Obtaining type information with Template Haskell

I'm currently working on a library that allows the user to specify a list of command specifications as follows: data CommandDef = forall (as :: [*]). Typeable as => CommandDef { argTypes :: Proxy as, commandName :: String, commandStrings ::…
Nathan BeDell
  • 2,263
  • 1
  • 14
  • 25
2
votes
1 answer

Haskell, Control.Lens: Couldn't match type ‘[Language.Haskell.TH.Syntax.Dec]’ with ‘Language.Haskell.TH.Syntax.Exp’

I want to learn how to use Control.Lens package. I tried to use an official tutorial. First of all, I haven't Control.Lens.Tutorial package. Is it important to reproduce the examples? I started GHCi and loaded TemplateHaskell extension: Prelude>…
2
votes
1 answer

TemplateHaskell not installed... then it is

I'm writing a program in Haskell, and it involves a lot of parentheses. So to clear up that ugly mess, I use the $ operator a couple of times to make it easier to read. For example: longFunc arg1 (anotherFunc (yetAnotherFunc arg2)) is replaced…
2
votes
1 answer

Avoiding orphan instances when defining instances with template haskell

I want to define a Haskell module that exports a class C and instances of C for various types. Because I want to define a lot of instances, that can be defined automatically following a given scheme, I defined a helper TH function to define the…
Kritzefitz
  • 2,644
  • 1
  • 20
  • 35
2
votes
2 answers

How can I turn a [TExp a] into a TExp [a], or otherwise apply refineTH to multiple values programatically?

I've been using refined for refinement types in Haskell recently, and have encountered a major usability problem. I can't figure out how to refine an entire list of values at compile time. For example I can write: {-# LANGUAGE TemplateHaskell…
2
votes
1 answer

How to check my implementation of a function which generates an infinite list?

Write a function that takes the function f and the number n and returns the list [f n, f (n + 1), f (n + 2), f (n + 3), f (n + 4) ... ]. Here is my solution: func f n = f n : func f (n+1) But I'm not sure that it is correct. How can I check my…
Silver
  • 101
  • 1
  • 1
  • 6
2
votes
1 answer

Get name of the constructor

I'm trying to find a way to be able to get name of my datatype constructor as String data Test = Foo { a :: Int , b :: Int } | Bar { a :: Int } | Lol | Lel String I'm searching something in form of name :: Constructor…
majkrzak
  • 1,332
  • 3
  • 14
  • 30
2
votes
1 answer

Mystery of subsite types

I can not figure out what types should go in my Foundation.hs when implementing type classes from the authentication plugin / it's use of the auth subsite: I can feel that I am very close, but I lack understanding. I am simply trying to use a…
2
votes
1 answer

How can I see a specific file's generated template haskell code when using yesod

Because of some bad input, a Template Haskell function is generating broken code. How can I apply -ddump-splices to just one file in Yesod? I know that fixing the bad input is the solution, but debugging that depends on what is being generated by…
2
votes
0 answers

See implicit exports from a Module

Quite surprisingly, I'm trying to fix a compilation warning missing-export-lists by adding explicitly the elements imported one by one for a specific module, but somehow there is something magical that this module is implicitly exporting that I…
Nicolas Henin
  • 3,244
  • 2
  • 21
  • 42
2
votes
0 answers

sizeof, offsetof, and alignment via TemplateHaskell

I wonder if someone has implemented analogues of hsc2hs pragmas via TemplateHaskell? It feels like it should be doable, since TH runs on target platform at compile time, and GHC always has a C compiler lying around. This could be useful as another…
artem
  • 363
  • 1
  • 9