<div dir="ltr"><div style class="markdown-here-wrapper" id="markdown-here-wrapper-961206"><p style="margin:1.2em 0px!important">There&#39;s a <a href="http://ghc.haskell.org/trac/ghc/blog/Template%20Haskell%20Proposal#PartD:quasiquotation">proposal</a> for adding a proper Haskell <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px 3px 3px 3px;display:inline">QuasiQuoter</code> as part of template-haskell.  Until then, as others have noted your best option is the <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px 3px 3px 3px;display:inline">haskell-src-meta</code> package, but be aware that this uses a separate parser.</p>


</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Aug 24, 2013 at 11:36 AM, TP <span dir="ltr">&lt;<a href="mailto:paratribulations@free.fr" target="_blank">paratribulations@free.fr</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi everybody,<br>
<br>
I continue to learn and test Template Haskell (one more time thanks to John<br>
Lato for his post at:<br>
<br>
<a href="http://www.mail-archive.com/haskell-cafe@haskell.org/msg106696.html" target="_blank">http://www.mail-archive.com/haskell-cafe@haskell.org/msg106696.html</a><br>
<br>
that made me understand a lot of things).<br>
<br>
I have a question about the way Template Haskell is working. Why Template<br>
Haskell does not propose something similar to Python (or bash) exec() or<br>
eval(), i.e. does not offer the possibility to take a (quoted) string in<br>
input, to make abstract syntax in output (to be executed later in a splice<br>
$()).<br>
For example, in Python, to make an affectation &#39;a=&quot;a&quot;&#39; programatically, I<br>
can simply do (at runtime; even if I am here only concerned with what<br>
Template Haskell could do, i.e. at compile time):<br>
&gt; def f(s): return &#39;%s = \&#39;%s\&#39;&#39; % (s,s)<br>
&gt; exec(f(&quot;a&quot;))<br>
&gt; a<br>
&#39;a&#39;<br>
<br>
With Template Haskell, I am compelled to make a function returning the<br>
abstract syntax corresponding to variable declaration:<br>
<br>
ValD (VarP $ mkName s) (NormalB $ LitE $ StringL s)<br>
<br>
(see complete example in Post Scriptum).<br>
This works fine, but it is less direct. I am sure that the Template Haskell<br>
approach has many advantages, but I am unable to list them. I think it is<br>
important to have the reasons in mind. Could you help me?<br>
<br>
Thanks in advance,<br>
<br>
TP<br>
<br>
<br>
PS: the complete Haskell example:<br>
<br>
-----------------------------------<br>
module MakeVard where<br>
import <a href="http://Language.Haskell.TH" target="_blank">Language.Haskell.TH</a><br>
<br>
makeVard :: Monad m =&gt; String -&gt; m [Dec]<br>
-- Equivalent to &quot;%s = \&quot;%s\&quot;&quot;<br>
makeVard s = return [ ValD (VarP $ mkName s) (NormalB $ LitE $ StringL s) []<br>
]<br>
-----------------------------------<br>
<br>
tested by<br>
<br>
-----------------------------------<br>
{-# LANGUAGE TemplateHaskell #-}<br>
import MakeVard<br>
<br>
$(makeVard &quot;a&quot;)<br>
<br>
main = do<br>
<br>
print a<br>
-----------------------------------<br>
<br>
resulting in<br>
$ runghc -ddump-splices test.hs<br>
test_makeVar.hs:1:1: Splicing declarations<br>
    makeVard &quot;a&quot;<br>
  ======&gt;<br>
    test_makeVar.hs:4:3-14<br>
    a = &quot;a&quot;<br>
&quot;a&quot;<br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br></div>