Template haskell helper
Rene de Visser
Rene_de_Visser at hotmail.com
Tue Aug 15 13:19:26 EDT 2006
Hello,
I have hacked together some untested haskell code to do the following
z8 = printTH [d| instance TH_Render Char1 where
render x = HsLit $ HsChar $ 'a' |]
results in something like
$(sequence [(instanceD (cxt [])
(appT (conT (mkName "TH_Render")) (conT (mkName "Char1")))
[(funD (mkName "render")
[(clause [(varP (mkName "x"))]
(normalB
(infixE (Just (conE (mkName "HsLit"))) (varE (mkName "$"))
(Just
(infixE (Just (conE (mkName "HsChar"))) (varE (mkName
"$"))
(Just (litE (CharL 'a')))))))
[])])])])
(minus the "$(sequence )")
which you can then be pasted into your program and modified.
Hopefully this will people get started with template haskell (and save me a
little bit of typing).
Rene.
begin 666 TH_render.hs
M>RTC($]05$E/3E, at +69G;&%S9V]W+65X=', at +69T:" C+7T-"GLM(R!/4%1)
M3TY3("UF86QL;W<M;W9E<FQA<'!I;F<M:6YS=&%N8V5S(",M?0T*;6]D=6QE
M(%1(7W1O;VQS+E1(7W)E;F1E<B!W:&5R90T*#0II;7!O<G0 at 3&%N9W5A9V4N
M2&%S:V5L;"Y42 T*:6UP;W)T($QA;F=U86=E+DAA<VME;&PN5$@N4WEN=&%X
M#0H-"FEM<&]R="!,86YG=6%G92Y(87-K96QL+E!A<G-E<@T*:6UP;W)T($QA
M;F=U86=E+DAA<VME;&PN4')E='1Y#0II;7!O<G0 at 3&%N9W5A9V4N2&%S:V5L
M;"Y3>6YT87 at -"@T*:6UP;W)T(%1(7W1O;VQS+D)A<V4-"@T*#0HM+2!"=6EL
M9"!V87)I86)L92!A<F=U96UE;G0 at 8G5I;&1E<@T*8VQA<W, at 0G5I;&1(<T5X
M<"!A('(@=VAE<F4-"B @("!B=6EL9"<@.CH at 2'-%>' @+3X at 82 M/B!R#0H-
M"FEN<W1A;F-E("A42%]296YD97(@82D@/3X at 0G5I;&1(<T5X<"!A($AS17AP
M('=H97)E#0H@(" @8G5I;&0G(&P@>" ]($AS4&%R96X@)"!(<T%P<"!L("AR
M96YD97(@>"D-"@T*:6YS=&%N8V4@*%1(7U)E;F1E<B!A+"!42%]296YD97(@
M8BP at 0G5I;&1(<T5X<"!B('(I(#T^($)U:6QD2'-%>' @82 H8BT^<BD@=VAE
M<F4-"B @("!B=6EL9"<@;"!X('D@/2!B=6EL9"<@*$AS07!P(&P@*')E;F1E
M<B!X*2D@('D-"@T*("TM8G5I;&0 at .CH@9F]R86QL('(@82X@*$)U:6QD3&ES
M="!A('(I(#T^(&$@+3X@<@T*8G5I;&0 at 9G5N8R!X(#T at 8G5I;&0G("AF=6YC
M7V]U="!F=6YC*2!X#0H-"F-L87-S(%1(7U)E;F1E<B!S('=H97)E#0H@(')E
M;F1E<B Z.B!S("T^($AS17AP#0H-"FEN<W1A;F-E(%1(7U)E;F1E<B!$96,@
M=VAE<F4-"B @<F5N9&5R("A&=6Y$(&YA;64 at 8VQA=7-E<RD@/2!B=6EL9" G
M9G5N1"!N86UE(&-L875S97,-"B @<F5N9&5R("A686Q$('!A="!B;V1Y(&1E
M8W,I(#T at 8G5I;&0@)W9A;$0@<&%T(&)O9'D-"B @<F5N9&5R("A$871A1"!C
M>'0@;F%M93$@;F%M97,R(&-O;G,@;F%M97,S*2 ](&)U:6QD("=D871A1"!C
M>'0@;F%M93$@;F%M97,R(&-O;G,@;F%M97,S#0H@(')E;F1E<B H3F5W='EP
M940 at 8WAT(&YA;64Q(&YA;65S,B!C;VYS(&YA;65S,RD@/2!B=6EL9" G;F5W
M='EP940 at 8WAT(&YA;64Q(&YA;65S,B!C;VYS(&YA;65S,PT*("!R96YD97(@
M*%1Y4WEN1"!N86UE(&YA;65S('1Y<"D@/2!B=6EL9" G='E3>6Y$(&YA;64@
M;F%M97,@='EP#0H@(')E;F1E<B H0VQA<W-$(&-X="!N86UE(&YA;65S(&9U
M;F1E<', at 9&5C<RD@/2!B=6EL9" G8VQA<W-$(&-X="!N86UE(&YA;65S(&9U
M;F1E<', at 9&5C<PT*("!R96YD97(@*$EN<W1A;F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](&)U:6QD("=F;W)A;&Q4(&YA;65S(&-X="!T>7 -"B @
M<F5N9&5R("A687)4(&YA;64I(#T at 8G5I;&0@)W9A<E0@(&YA;64-"B @<F5N
M9&5R("A#;VY4(&YA;64I(#T at 8G5I;&0@)V-O;E0@(&YA;64-"B @<F5N9&5R
M("A4=7!L950@:6YT*2 ](&)U:6QD("=T=7!L950@:6YT#0H@(')E;F1E<B H
M07)R;W=4*2 ](&9U;F-?;W5T("=A<G)O=U0@(" -"B @<F5N9&5R("A,:7-T
M5"D@/2!F=6YC7V]U=" G;&ES=%0@( T*("!R96YD97(@*$%P<%0@='EP,2!T
M>7 R*2 ](&)U:6QD("=A<'!4('1Y<#$@='EP,B -"@T*:6YS=&%N8V4 at 5$A?
M4F5N9&5R(%-T<FEC="!W:&5R90T*("!R96YD97(@3F]T4W1R:6-T(#T at 9G5N
M8U]O=70@)VYO=%-T<FEC= T*("!R96YD97(@27-3=')I8W0@/2!F=6YC7V]U
M=" G:7-3=')I8W0-"@T*:6YS=&%N8V4 at 5$A?4F5N9&5R($9U;D1E<"!W:&5R
M90T*("!R96YD97(@*$9U;D1E<"!N86UE<S$@;F%M97,R*2 ](&5R<F]R(")R
M96YD97(@)V9U;D1E<"!N86UE<S$@;F%M97,R(@T*#0II;G-T86YC92!42%]2
M96YD97(@3F%M92!W:&5R90T*("!R96YD97(@;F%M92 ](&)U:6QD("=M:TYA
M;64@*&YA;65"87-E(&YA;64I#0H-"FEN<W1A;F-E(%1(7U)E;F1E<B!0870@
M=VAE<F4-"B @(')E;F1E<B H5F%R4"!N86UE*2 ](&)U:6QD("=V87)0(&YA
M;64-"@T*:6YS=&%N8V4 at 5$A?4F5N9&5R($)O9'D@=VAE<F4-"B @(')E;F1E
M<B H3F]R;6%L0B!E>' I(#T at 8G5I;&0@)VYO<FUA;$(@97AP#0H@("!R96YD
M97(@*$=U87)D961"(&=U87)D<RD@/2!B=6EL9" G9W5A<F1E9$(@(&=U87)D
M<PT*#0II;G-T86YC92!42%]296YD97(@4W1M="!W:&5R90T*(" @<F5N9&5R
M("A":6YD4R!P870 at 97AP*2 ](&)U:6QD("=B:6YD4R!P870 at 97AP#0H@("!R
M96YD97(@*$QE=%, at 9&5C<RD@/2!B=6EL9" G;&5T4R!D96-S#0H@("!R96YD
M97(@*$YO0FEN9%, at 97AP*2 ](&)U:6QD("=N;T)I;F13(&5X< T*(" @<F5N
M9&5R("A087)3('-T;71S<RD@/2!B=6EL9" G<&%R4R!S=&UT<W,-"@T*:6YS
M=&%N8V4 at 5$A?4F5N9&5R($5X<"!W:&5R90T*(" @<F5N9&5R("A687)%(&YA
M;64I(#T at 8G5I;&0@)W9A<D4@;F%M90T*(" @<F5N9&5R("A#;VY%(&YA;64I
M(#T at 8G5I;&0@)V-O;D4@;F%M92 @( T*(" @<F5N9&5R("A,:71%(&QI="D@
M/2!B=6EL9" @)VQI=$4@;&ET#0H@("!R96YD97(@*$%P<$4 at 97AP,2!E>' R
M*2 ](&)U:6QD("=A<'!%(&5X<#$@97AP,B -"B @(')E;F1E<B H3&%M12!P
M871S(&5X<"D@/2!B=6EL9" G;&%M12!P871S(&5X<" -"B @(')E;F1E<B H
M5'5P12!E>' I(#T at 8G5I;&0@)W1U<$4 at 97AP#0H@("!R96YD97(@*$-O;F1%
M(&5X<#$@97AP,B!E>' S*2 ](&)U:6QD("=C;VYD12!E>' Q(&5X<#(@97AP
M,R -"B @(')E;F1E<B H3&5T12!D96-S(&5X<"D@/2!B=6EL9" G;&5T12!D
M96-S(&5X<" -"B @(')E;F1E<B H0V%S944 at 97AP(&UA=&-H<RD@/2!B=6EL
M9" G8V%S944 at 97AP(&UA=&-H<PT*(" @<F5N9&5R("A$;T4@<W1M=',I(#T@
M8G5I;&0@)V1O12!S=&UT<PT*(" @<F5N9&5R("A#;VUP12!S=&UT<RD@/2!B
M=6EL9" G8V]M<$4@<W1M=',-"B @(')E;F1E<B H07)I=&A397%%(')A;F=E
M*2 ](&)U:6QD("=A<FET:%-E<44@<F%N9V4-"B @(')E;F1E<B H3&ES=$4@
M97AP<RD@/2!B=6EL9" G;&ES=$4 at 97AP<R -"B @(')E;F1E<B H4VEG12!E
M>' @='EP*2 ](&)U:6QD("=S:6=%(&5X<"!T>7 -"B @(')E;F1E<B H4F5C
M0V]N12!N86UE(&9I96QD17AP<RD@/2!B=6EL9" G<F5C0V]N12!N86UE(&9I
M96QD17AP<PT*(" @<F5N9&5R("A296-5<&1%(&5X<"!F:65L9$5X<',I(#T@
M8G5I;&0@)W)E8U5P9$4 at 97AP(&9I96QD17AP<PT*(" @<F5N9&5R("A);F9I
M>$4@;45X<#$@97AP(&U%>' R*2 ](&)U:6QD("=I;F9I>$4@;45X<#$@97AP
M(&U%>' R( T*#0II;G-T86YC92!42%]296YD97(@*$UA>6)E($5X<"D@=VAE
M<F4-"B @(')E;F1E<B H2G5S="!E>' I(#T at 8G5I;&0@)TIU<W0 at 97AP#0H@
M("!R96YD97(@3F]T:&EN9R ](&9U;F-?;W5T("=.;W1H:6YG#0H-"FEN<W1A
M;F-E(%1(7U)E;F1E<B!-871C:"!W:&5R90T*(" @<F5N9&5R("A-871C:"!P
M870 at 8F]D>2!D96-S*2 ](&)U:6QD("=M871C:"!P870 at 8F]D>2!D96-S#0H-
M"FEN<W1A;F-E(%1(7U)E;F1E<B!286YG92!W:&5R90T*(" @<F5N9&5R("A&
M<F]M4B!E>' I(#T at 8G5I;&0@)V9R;VU2(&5X< T*(" @<F5N9&5R("A&<F]M
M5&AE;E(@97AP,2!E>' R*2 ](&)U:6QD("=F<F]M5&AE;E(@97AP,2!E>' R
M#0H@("!R96YD97(@*$9R;VU4;U(@97AP,2!E>' R*2 @/2!B=6EL9" G9G)O
M;51O4B!E>' Q(&5X<#(-"B @(')E;F1E<B H1G)O;51H96Y4;U(@97AP,2!E
M>' R(&5X<#,I(#T at 8G5I;&0@)V9R;VU4:&5N5&]2(&5X<#$@97AP,B!E>' S
M( T*#0II;G-T86YC92!42%]296YD97(@*%-T<FEC="P at 5'EP92D@=VAE<F4-
M"B @<F5N9&5R("AS=')I8W0L('1Y<"D@/2!B=6EL9" G<W1R:6-T5'EP92!S
M=')I8W0@='EP#0H-"FEN<W1A;F-E(%1(7U)E;F1E<B H1W5A<F0L($5X<"D@
M=VAE<F4-"B @(')E;F1E<B H3F]R;6%L1R!G97AP+"!E>' I(#T at 8G5I;&0@
M)VYO<FUA;$=%(&=E>' @97AP#0H@("!R96YD97(@*%!A=$<@<W1M=',L(&5X
M<"D@/2!B=6EL9" G<&%T1T4@<W1M=',-"@T*:6YS=&%N8V4 at 5$A?4F5N9&5R
M("A.86UE+"!%>' I('=H97)E#0H@("!R96YD97(@*&YA;64L(&5X<"D@/2!B
M=6EL9" G9FEE;&1%>' @;F%M92!E>' -"@T*:6YS=&%N8V4@*%1(7U)E;F1E
M<B!A*2 ]/B!42%]296YD97(@6V%=('=H97)E#0H@("!R96YD97(@;&ES=" ]
M($AS3&ES=" H;6%P(')E;F1E<B!L:7-T*0T*#0II;G-T86YC92!42%]296YD
M97(@6U1Y<&5=('=H97)E#0H@(')E;F1E<B!C>'1S(#T at 2'-087)E;B D("AF
M=6YC7V]U=" G8WAT*2!@2'-!<'!@("A(<TQI<W0@)"!M87 @<F5N9&5R(&-X
M=',I#0H-"FEN<W1A;F-E(%1(7U)E;F1E<B!3=')I;F<@=VAE<F4-"B @<F5N
M9&5R('-T<FEN9R ]($AS3&ET("0 at 2'-3=')I;F<@<W1R:6YG#0H@#0II;G-T
M86YC92!42%]296YD97(@3&ET('=H97)E#0H@("!R96YD97(@*$EN=&5G97),
M(&EN="D@/2!B=6EL9" G26YT96=E<DP@:6YT#0H@("!R96YD97(@*$-H87),
M(&-H87(I(#T at 8G5I;&0@)T-H87),(&-H87(-"B @(" @(" @(" @(" @(" @
M(" @(" @(" @(" @(" @(" @(" @(" -"FEN<W1A;F-E(%1(7U)E;F1E<B!)
M;G1E9V5R('=H97)E#0H@("!R96YD97(@:6YT(" ]("A(<TQI=" H2'-);G0@
M:6YT*2D@( T*#0II;G-T86YC92!42%]296YD97(@26YT('=H97)E#0H@("!R
M96YD97(@:6YT(" ]("A(<TQI=" H2'-);G0@)"!F<F]M26YT96=R86P@:6YT
M*2D-"@T*:6YS=&%N8V4 at 5$A?4F5N9&5R($-H87(@=VAE<F4-"B @<F5N9&5R
M(&-H87(@(#T@*$AS3&ET("A(<T-H87(@8VAA<BDI#0H-"F9U;F-?;W5T(&8@
M/2!(<U9A<B D(%5N475A;" D($AS261E;G0@)"!N86UE0F%S92!F#0H-"@T*
M<F5N9&5R7V%L;" Z.B H36]N860@;2D@/3X@;2!;1&5C72 M/B!M(%M(<T5X
M<%T-"G)E;F1E<E]A;&P at 9&5C<R ](&1O(&1E8W,G(#PM(&1E8W,-"B @(" @
M(" @(" @(" @(" @(" @(')E='5R;B D("AM87 @<F5N9&5R(&1E8W,G*0T*
M#0IZ-2 ](%MD?"!X(#T@,7Q=(" @(" @(" @(" @(" @(" @(" @( T*>#(@
M/2!P<FEN=$%35" D(')E;F1E<E]A;&P@>C4-"BTM('@S(#T@<#(@>#(@#0H-
M"@T*+2T at 0V%N(&%L=V%Y<R!U<V4@;6%T8VAI;F<@:&5R92!T;R!R96UO=F4@
M;W5T97)M;W-T("@I#0IP<FEN=%1((#HZ(%$@6T1E8UT at +3X@24\@*"D-"G!R
M:6YT5$@@9&5C<R ](&1O(&1E8W,G(#PM(')U;E$@)"!R96YD97)?86QL(&1E
M8W,-"B @(" @(" @(" @(" @(" @('!U=%-T<B D('!R971T>5!R:6YT("0@
M2'-,:7-T(&1E8W,G#0H@(" @(" @(" @(" @(" @("!P=713='(@(EQN(@T*
M#0IN97=T>7!E($-H87(Q(#T at 0VAA<C$@0VAA<@T*#0IZ-R ]('!R:6YT5$@@
M>C4-"GHX(#T@<')I;G142"!;9'P@:6YS=&%N8V4 at 5$A?4F5N9&5R($-H87(Q
M('=H97)E#0H@(" @(" @(" @(" @(" @(" @(" @("!R96YD97(@>" ]($AS
M3&ET("0 at 2'-#:&%R("0@)V$G('Q=#0H-"GDQ(#T@<')I;G1!4U0 at 6V1\(&EN
M<W1A;F-E(%1(7U)E;F1E<B!#:&%R,2!W:&5R90T*(" @(" @(" @(" @(" @
M(" @(" @(" @<F5N9&5R('@@/2!(<TQI=" D($AS0VAA<B D("=A)R!\70T*
M#0HD*'-E<75E;F-E(%LH:6YS=&%N8V5$("AC>'0 at 6UTI#0H@(" @*&%P<%0@
M*&-O;E0@*&UK3F%M92 B5$A?4F5N9&5R(BDI("AC;VY4("AM:TYA;64@(D-H
M87(Q(BDI*0T*(" @(%LH9G5N1" H;6M.86UE(")R96YD97(B*0T*(" @(" @
M("!;*&-L875S92!;*'9A<E @*&UK3F%M92 B>"(I*5T-"B @(" @(" @(" @
M("AN;W)M86Q"#0H@(" @(" @(" @(" @(" H:6YF:7A%("A*=7-T("AC;VY%
M("AM:TYA;64@(DAS3&ET(BDI*2 H=F%R12 H;6M.86UE("(D(BDI#0H@(" @
M(" @(" @(" @(" @(" H2G5S= T*(" @(" @(" @(" @(" @(" @(" @*&EN
M9FEX12 H2G5S=" H8V]N12 H;6M.86UE(")(<T-H87(B*2DI("AV87)%("AM
M:TYA;64@(B0B*2D-"B @(" @(" @(" @(" @(" @(" @(" @("A*=7-T("AL
M:71%("A#:&%R3" G82<I*2DI*2DI#0H@(" @(" @(" @("!;72E=*5TI72D-
!"@``
`
end
begin 666 Base.hs
M>RTC($]05$E/3E, at +69G;&%S9V]W+65X=', at +69T:" C+7T-"FUO9'5L92!4
M2%]T;V]L<RY"87-E('=H97)E#0H-"FEM<&]R="!,86YG=6%G92Y(87-K96QL
M+E1(#0II;7!O<G0 at 3&%N9W5A9V4N2&%S:V5L;"Y42"Y3>6YT87 at -"@T*:6YS
M=&%N8V4 at 4VAO=R!);F9O('=H97)E#0H@('-H;W<@*%1Y0V]N22!D96,I(#T@
M(E1Y0V]N22 D("(@*RL@<VAO=R!D96,-"@T*<')I;G1!4U0 at .CH@*%-H;W<@
M82D@/3X at 42!A("T^($E/("@I#0IP<FEN=$%35" @87-T(#T@<G5N42!A<W0@
M/CX]('!U=%-T<DQN("X@<VAO=PT*#0IP<FEN=$-O9&4 at .CH@*%!P<B!A*2 ]
M/B!1(&$@+3X at 24\@*"D-"G!R:6YT0V]D92!A<W0@/2!R=6Y1(&%S=" ^/CT@
M<'5T4W1R3&X at +B!P<')I;G0-"@T*=&5S=%]P<FEN="!Q=6%S:2 ](&1O('MD
D(#PM(')U;E$@)"!Q=6%S:2 [("!P<FEN="!D?0T*#0H-"@T*
`
end
More information about the Libraries
mailing list