I&#39;m trying to learn Template Haskell.<div><br></div><div>I decided to try to write a mapTup function which takes function and a tuple (e.g. mapTup id (1,&quot;hi&quot;,&#39;a&#39;) ) and, well, applies the function to each cell.</div>
<div><br></div><div>The closest I&#39;ve gotten so far is this:</div><div><br></div><div><div>&gt; {-# LANGUAGE TemplateHaskell #-}</div><div>&gt; module MapTup</div><div>&gt; where</div><div>&gt; import <a href="http://Language.Haskell.TH">Language.Haskell.TH</a></div>
<div>&gt; import Control.Monad</div><div>&gt; </div><div>&gt; mapTup fun tup = do</div><div>&gt;   funE &lt;- runQ $ [| $fun |]</div><div>&gt;   TupE tupContents &lt;- runQ $ [| $tup |]</div><div>&gt;   return $ TupE $ map (AppE funE) tupContents</div>
<div><br></div><div>The problem is that I can&#39;t figure out how to get the representation of the values bound to fun and tup.</div><div><br></div><div>Sorry if I&#39;m wording this badly.  My head hurts from meta-programming ;)</div>
<br>-- <br>          Alex R<br>
</div>