Add UNPACK support to Template Haskell
I've just hacked it in:
$ ghci -XTemplateHaskell
GHCi, version 7.1.20110630: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
λ> import Language.Haskell.TH
λ> runQ [d| data T = T {-# UNPACK #-} !Int |]
Loading package array-0.3.0.2 ... linking ... done.
Loading package containers-0.4.0.0 ... linking ... done.
Loading package pretty-1.0.2.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
[DataD [] T [] [NormalC T [(Unpacked,ConT GHC.Types.Int)]] []]
λ>
TH.hs:
{-# LANGUAGE TemplateHaskell #-}
module TH where
import Language.Haskell.TH
d :: Q [Dec]
d = return [DataD [] n [] [NormalC n [(Unpacked,ConT ''Int)]] []]
where n = mkName "T"
Main.hs:
{-# LANGUAGE TemplateHaskell #-}
import TH
$(d)
instance Show T where
show (T i) = show i
main = putStrLn $ show (T 10)
Compiling and running:
$ ghc -ddump-splices -fforce-recomp Main.hs
[1 of 2] Compiling TH ( TH.hs, TH.o )
[2 of 2] Compiling Main ( Main.hs, Main.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Loading package pretty-1.0.2.0 ... linking ... done.
Loading package array-0.3.0.2 ... linking ... done.
Loading package containers-0.4.0.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
Main.hs:1:1: Splicing declarations
d
======>
Main.hs:5:3
data T = T {-# UNPACK #-} !Int
Linking Main ...
$ ./Main
10
Please consider merging.
Trac metadata
Trac field | Value |
---|---|
Version | 7.1 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Template Haskell |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |