template-haskell

How can QuickCheck test all properties for each sample

天大地大妈咪最大 提交于 2021-02-07 19:22:15
问题 ...instead of generating 100 new random samples for each property? My testsuite contains the TemplateHaskell hack explained here [1] to test all functions named prop_*. Running the test program prints === prop_foo from tests/lala.lhs:20 === +++ OK, passed 100 tests. === prop_bar from tests/lala.lhs:28 === +++ OK, passed 100 tests. and it looks like going through 100 random samples for each of the properties. Problemis: Generating the samples is quite expensive, checking the properties is not.

How can QuickCheck test all properties for each sample

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-07 19:20:04
问题 ...instead of generating 100 new random samples for each property? My testsuite contains the TemplateHaskell hack explained here [1] to test all functions named prop_*. Running the test program prints === prop_foo from tests/lala.lhs:20 === +++ OK, passed 100 tests. === prop_bar from tests/lala.lhs:28 === +++ OK, passed 100 tests. and it looks like going through 100 random samples for each of the properties. Problemis: Generating the samples is quite expensive, checking the properties is not.

Retrieving annotations from the same module

陌路散爱 提交于 2020-01-15 23:01:29
问题 Suppose I define my own annotation type: {-# LANGUAGE DeriveDataTypeable #-} module Def where import Data.Data data MyAnn = MyAnn Int deriving (Show, Typeable, Data) and some Template Haskell function to access it: module TH where import Def import Language.Haskell.TH.Syntax myAnn :: Name -> Q Exp myAnn name = do [MyAnn x] <- reifyAnnotations (AnnLookupName name) lift x I would now like to use it like this: {-# LANGUAGE TemplateHaskell #-} module Client where import Def import TH x :: () x =

Evaluating a function at compile time with Template Haskell

孤街浪徒 提交于 2020-01-13 08:21:31
问题 I am writing a simple HashString class, which is just a string and its hash: data HashString = HashString Int -- ^ hash T.Text -- ^ string! Now I'm trying to generate these at compile time with something like: $(hString "hello, world") :: HashString I want the hash, and the text packing to happen at compile time. How do I do this? Here's what I've tried so far, but I'm not sure if its right, nor am I sure it does everything at compile time: hString :: String -> Q Exp hString s = [| HashString

Template Haskell: Is there a function (or special syntax) that parses a String and returns Q Exp?

守給你的承諾、 提交于 2020-01-09 19:46:09
问题 I am trying to learn a bit of Template Haskell and Quasi Quotation, and I am looking for a function that takes a String and parses it to Q Exp , so the type is: String -> Q Exp Tried searching hoogle, but the results I saw had to do with lifting String literals to Q Exp , and the closest I found was Language.Haskell.TH.dyn which does quite what I want, but only for a single variable. Are there other options? E.g. a special syntax? I'm just in the process of familiarizing myself with [||] and

Template Haskell: Is there a function (or special syntax) that parses a String and returns Q Exp?

别来无恙 提交于 2020-01-09 19:44:46
问题 I am trying to learn a bit of Template Haskell and Quasi Quotation, and I am looking for a function that takes a String and parses it to Q Exp , so the type is: String -> Q Exp Tried searching hoogle, but the results I saw had to do with lifting String literals to Q Exp , and the closest I found was Language.Haskell.TH.dyn which does quite what I want, but only for a single variable. Are there other options? E.g. a special syntax? I'm just in the process of familiarizing myself with [||] and

Template Haskell compile error when calling with different parameters

放肆的年华 提交于 2020-01-04 08:24:26
问题 Why does the following fail to compile (on GHC 7.4.2)? {-# LANGUAGE TemplateHaskell #-} f1 = $([| id |]) main = print $ (f1 (42 :: Int), f1 (42 :: Integer)) Note that the following compiles fine: {-# LANGUAGE TemplateHaskell #-} f1 = id -- Don't use template Haskell here. main = print $ (f1 (42 :: Int), f1 (42 :: Integer)) Is there a language extension I can use to make the former compile? I know the Template Haskell seems silly in this example, but it's a simplified version of a more complex

Template Haskell compile error when calling with different parameters

陌路散爱 提交于 2020-01-04 08:24:26
问题 Why does the following fail to compile (on GHC 7.4.2)? {-# LANGUAGE TemplateHaskell #-} f1 = $([| id |]) main = print $ (f1 (42 :: Int), f1 (42 :: Integer)) Note that the following compiles fine: {-# LANGUAGE TemplateHaskell #-} f1 = id -- Don't use template Haskell here. main = print $ (f1 (42 :: Int), f1 (42 :: Integer)) Is there a language extension I can use to make the former compile? I know the Template Haskell seems silly in this example, but it's a simplified version of a more complex

Functions as arguments to be used in template haskell quote

十年热恋 提交于 2020-01-03 16:46:14
问题 This is partially a followup to Lift instance for a function?. However, the answer there is to either globally define the function or to rewrite it inside the quotation. However, we will be using foo a lot with different functions for f from within the scope of a let . This makes it just about impossible for us to define multiple global version of f. The latter solution, of writing our function within the quote, seem equivalent to writing a lift on functions. So, is there any way of lifting

Template Haskell type quoting problems

丶灬走出姿态 提交于 2020-01-03 09:57:29
问题 The TemplateHaskell quoting documents two quotes ( '' ) as the way to get the Name of a type: > ''String GHC.Base.String This works fine for this type (name). However, I can't find a way to make it work nice for e.g. Maybe String : > ''Maybe String -- interprets String as a data constructor > ''Maybe ''String -- wants to apply ''String to the Name type I know I can workaround via using [t| Maybe String |] , but this is then in the Q monad, and requires type changes, and I think is not type