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

Using a declaration quoter in a where statement

I am implementing a DSL that is based on using standard haskell functions/combinators to build database queries. From an implementation POV I decided to represent variables in the query like this: newtype Variable = Var { fromVar :: Text } this…
Fabian Schneider
  • 799
  • 1
  • 13
  • 40
1
vote
1 answer

Is it possible to derive a `Lift` (or `Data`) instance for Blazes `Html`?

I am trying to parse some markdown at compile time and hold on to the Html instance it generates. Normally I would do something like this using a derived Language.Haskell.TH.Lift.Lift instance: -- Lib.hs …
patrick
  • 11
  • 1
1
vote
0 answers

Using a Barbie type as a field in another Barbie type with Barbies-TH

I'd like to use Barbies-TH to create two Barbie records, where one is used as a field type in the other: data Player = MkPlayer { playerLeft, playerRight, playerShoot, playerStart :: Bool } data Inputs = MkInputs { player1, player2 ::…
Cactus
  • 27,075
  • 9
  • 69
  • 149
1
vote
1 answer

Converting Haskell to Template Haskell: couldn't match expected type ExpQ

I had the following Haskell code (just a fragment of all code, but works): data ByteCode t where INT :: Int -> ByteCode Int BOOL:: Bool -> ByteCode Bool Add :: ByteCode Int -> ByteCode Int -> ByteCode Int Mul :: ByteCode Int ->…
pmichaels
  • 139
  • 6
1
vote
1 answer

Template Haskell do variable assignment clarification

I am looking at the following TH code, and have several questions marked by --: newtype C a = C ExpQ unC (C x) = x --what is the significance of this clift1 :: ExpQ -> C t -> C a --why are the C's here followed by t and a clift1 g (C x) = C $…
pmichaels
  • 139
  • 6
1
vote
1 answer

How do I use Aeson to generate a literal (unquoted) javascript expression?

i'm using this function and need to pass it an Aeson Value: { logLevel : vega.Debug } this is supposed to refer to an enum in a javascript package that the binding doesn't export. afaict i'm supposed to use Data.Aeson.QQ.Simple for this, but…
user1441998
  • 459
  • 4
  • 14
1
vote
2 answers

Retrieving the size of a Bounded Enum as a Nat

For a library I'm writing, I would like to be able to retrieve the size of any type with Bounded and Enum constraints, as a type-level Nat. The purpose is to define typeclass instances such as: instance ( Enum a, Bounded a, n ~ BoundedEnumSize a )…
Sam Derbyshire
  • 719
  • 1
  • 4
  • 12
1
vote
1 answer

Defining Own Data Type in Haskell Where clause

data Geometry = Point {xCoord:: Double ,yCoord:: Double} |Line {xCoeff:: Double ,yCoeff:: Double ,constant:: Double}|Plane {xCoeff:: Double,yCoeff:: Double, …
device
  • 95
  • 6
1
vote
2 answers

How to get the current UTC time in Haskell?

i want to use system time in my code for having the record of time when the data is captured from the user interface.how to get system time using Haskell.
1
vote
2 answers

Template Haskell: zipn

I was reading a Template Haskell tutorial from archive.org since it was lost from haskell.org, and noticed that it is corrupted, as if random parts had been taken out. I was hoping to read about their implementation of zipn. The only code they have…
Muchin
  • 4,887
  • 4
  • 23
  • 25
1
vote
1 answer

Eval expression during compilation and treat runtime errors as compilation errors

I am working on a simple programming language interpreter in Haskell and I have a bit of trouble while defining standard library. I would like it to be defined as a static string at the toplevel and compiled along with my interpreter: stdLibStr ::…
radrow
  • 6,419
  • 4
  • 26
  • 53
1
vote
1 answer

Derive positional Show

Notice how T 5 shows in > newtype T = T { getT :: Int } deriving Show > T 5 T {getT = 5} Is there some way to derive the positional, non-record-syntax variant of Show for a type that was declared with record syntax? (btw T is only a simple example…
yairchu
  • 23,680
  • 7
  • 69
  • 109
1
vote
1 answer

How to convert a Type (from TemplateHaskell) to a Proxy?

I'm neck deep in some complex TemplateHaskell and am desperately looking for a function with the following type signature: Language.Haskell.TH.Type -> Data.Proxy.Proxy a Does something like this exist? I can appreciate that it would be hard to…
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
1
vote
0 answers

How do I use GHCSlave without signing errors?

I have gotten ghc-slave to build for an iPhone 6S running iOS 12.0.1. I put this into a helper script so that I don't confuse cabal with constantly changing IP addresses: connect_to_iphone #!/bin/bash exec iserv-proxy "$@" I…
HTNW
  • 27,182
  • 1
  • 32
  • 60
1
vote
1 answer

How to "apply" a type-variable in Template Haskell?

I'm passing a record with the following structure to a Template Haskell function: module Editor.App where data WithMaybe data WithoutMaybe type family TypeSelector a b where TypeSelector WithMaybe b = Maybe b TypeSelector WithoutMaybe b =…
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60