Created
July 12, 2013 10:18
-
-
Save bennofs/5983373 to your computer and use it in GitHub Desktop.
Template Haskell: Generate unique data type names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ghci -ddump-splices test2.hs 12:17:44 | |
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help | |
Loading package ghc-prim ... linking ... done. | |
Loading package integer-gmp ... linking ... done. | |
Loading package base ... linking ... done. | |
[1 of 2] Compiling THTest ( THTest.hs, interpreted ) | |
[2 of 2] Compiling Test ( test2.hs, interpreted ) | |
Loading package array-0.4.0.1 ... linking ... done. | |
Loading package deepseq-1.3.0.1 ... linking ... done. | |
Loading package containers-0.5.0.0 ... linking ... done. | |
Loading package pretty-1.1.1.0 ... linking ... done. | |
Loading package template-haskell ... linking ... done. | |
test2.hs:1:1: Splicing declarations | |
spliceDataDecs | |
======> | |
test2.hs:6:1-14 | |
data EmptyData_a152 | |
test2.hs:1:1: Splicing declarations | |
spliceDataDecs | |
======> | |
test2.hs:7:1-14 | |
data EmptyData_a156 | |
test2.hs:7:1: | |
Multiple declarations of `EmptyData' | |
Declared at: test2.hs:6:1 | |
test2.hs:7:1 | |
Failed, modules loaded: THTest. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TemplateHaskell #-} | |
module Test where | |
import THTest | |
spliceDataDecs | |
spliceDataDecs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module THTest where | |
import Language.Haskell.TH | |
import Control.Monad | |
spliceDataDecs :: Q [Dec] | |
spliceDataDecs = do | |
names <- replicateM 1 $ newName "EmptyData" | |
return $ map (\n -> DataD [] n [] [] []) names |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment