<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.Code, li.Code, div.Code
        {mso-style-name:Code;
        mso-style-link:"Code Char";
        margin:0cm;
        margin-bottom:.0001pt;
        text-indent:36.0pt;
        font-size:12.0pt;
        font-family:"Courier New";}
span.CodeChar
        {mso-style-name:"Code Char";
        mso-style-link:Code;
        font-family:"Courier New";
        mso-fareast-language:EN-GB;}
span.hoenzb
        {mso-style-name:hoenzb;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
.MsoPapDefault
        {mso-style-type:export-only;
        margin-top:6.0pt;
        margin-right:0cm;
        margin-bottom:6.0pt;
        margin-left:0cm;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;mso-fareast-language:EN-US">What Edward says also applies to code quotations.  So, for example:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="Code"><span style="mso-fareast-language:EN-US">module M<o:p></o:p></span></p>
<p class="Code" style="margin-left:36.0pt"><span style="mso-fareast-language:EN-US">import IntSet<o:p></o:p></span></p>
<p class="Code" style="margin-left:36.0pt"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="Code" style="margin-left:36.0pt"><span style="mso-fareast-language:EN-US">f :: Q Exp -> Q Exp<o:p></o:p></span></p>
<p class="Code" style="margin-left:36.0pt"><span style="mso-fareast-language:EN-US">f blah = [|  fromList $blah |]<o:p></o:p></span></p>
<p class="Code"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="Code"><span style="mso-fareast-language:EN-US">module N where<o:p></o:p></span></p>
<p class="Code"><span style="mso-fareast-language:EN-US">     import M<o:p></o:p></span></p>
<p class="Code"><span style="mso-fareast-language:EN-US">     h x = $(f [| [x,x] |])<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;mso-fareast-language:EN-US">The splice expands to (fromList [x,x]), but the fromList guaranteed to be the fromList in scope where f is defined (in M), and NOT whatever other fromList might be
 in scope at the splice site in N.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;mso-fareast-language:EN-US">Moreover, you do not need to import IntSet.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;mso-fareast-language:EN-US">I hope that helps.  Would someone like to add a section to
<a href="https://wiki.haskell.org/Template_Haskell">https://wiki.haskell.org/Template_Haskell</a>, to explain?  There are several tutorials there as well.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;mso-fareast-language:EN-US">Simon<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Calibri",sans-serif;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Glasgow-haskell-users [mailto:glasgow-haskell-users-bounces@haskell.org]
<b>On Behalf Of </b>Edward Kmett<br>
<b>Sent:</b> 17 March 2015 05:01<br>
<b>To:</b> J. Garrett Morris<br>
<b>Cc:</b> GHC users<br>
<b>Subject:</b> Re: Qualified names in TH?<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
Using {-# LANGUAGE TemplateHaskell #-} you can use 'foo and ''Foo to get access to the names in scope in the module that is building the splice, rather than worrying about what names are in scope in the module the code gets spliced into.<o:p></o:p></p>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
-Edward<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
On Mon, Mar 16, 2015 at 10:54 PM, J. Garrett Morris <<a href="mailto:Garrett.Morris@ed.ac.uk" target="_blank">Garrett.Morris@ed.ac.uk</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
I'm trying to write some Template Haskell code that (among other<br>
things) manipulates IntSets.  So, for example, I'd like a splice to<br>
generate a call to Data.IntSet.fromList.  However, I'm not sure how<br>
IntSet will be imported in the target module.  Is there a way to<br>
resolve the fully qualified name (or similar) to a TH Name, without<br>
having to know how it's imported in the splicing module?  (The obvious<br>
approach---mkName "Data.IntSet.fromList"---seems not to work in GHC<br>
7.8.)<br>
<br>
Thanks!<br>
<span style="color:#888888"><br>
<span class="hoenzb"> /g</span><br>
<br>
<span class="hoenzb">--</span><br>
<span class="hoenzb">The University of Edinburgh is a charitable body, registered in</span><br>
<span class="hoenzb">Scotland, with registration number SC005336.</span><br>
<br>
<span class="hoenzb">_______________________________________________</span><br>
<span class="hoenzb">Glasgow-haskell-users mailing list</span><br>
<span class="hoenzb"><a href="mailto:Glasgow-haskell-users@haskell.org">Glasgow-haskell-users@haskell.org</a></span><br>
<span class="hoenzb"><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users</a></span></span><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:6.0pt;margin-right:0cm;margin-bottom:6.0pt;margin-left:0cm">
<o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>