I'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,"hi",'a') ) and, well, applies the function to each cell.</div>
<div><br></div><div>The closest I've gotten so far is this:</div><div><br></div><div><div>> {-# LANGUAGE TemplateHaskell #-}</div><div>> module MapTup</div><div>> where</div><div>> import <a href="http://Language.Haskell.TH">Language.Haskell.TH</a></div>
<div>> import Control.Monad</div><div>> </div><div>> mapTup fun tup = do</div><div>> funE <- runQ $ [| $fun |]</div><div>> TupE tupContents <- runQ $ [| $tup |]</div><div>> return $ TupE $ map (AppE funE) tupContents</div>
<div><br></div><div>The problem is that I can't figure out how to get the representation of the values bound to fun and tup.</div><div><br></div><div>Sorry if I'm wording this badly. My head hurts from meta-programming ;)</div>
<br>-- <br> Alex R<br>
</div>