title: Haskell Programmatically/Dynamically Define Functions
body: <p>I'm looking for a way to dynamically define functions in Haskell, or for Haskell's idiomatic equivilent of which I'm clearly not aware.</p>
  
  <p>The scenario is as follows: I have a <code>tagWithAttrs</code> function that generates new functions based on the provided <code>String</code> argument. The definition looks something like this:</p>
  
  <pre><code>tagWithAttrs :: String -&gt; ([(String, String)] -&gt; [String] -&gt; String)
  tagWithAttrs tagName = [...]  -- Implementation ommited to save room.
  
  h1 :: [(String, String)] -&gt; [String] -&gt; String
  h1 = tagWithAttrs "h1"
  
  main :: IO ()
  main = putStrLn $ h1 [("id", "abc"), ("class", "def")] ["A H1 Test"]
  
  -- Should display '&lt;h1 id="abc" class="def"&gt;A H1 Test&lt;/h1&gt;'.
  </code></pre>
  
  <p>So far so good. But the line in which I assign <code>h1</code> is one of many, since I'd have to do that for every single HTML tag I'm defining. In Python, I'd loop over a list of the HTML tag names, inserting each respective result from <code>tag_with_attrs</code> into the dictionary returned by <code>globals()</code>. In short, I'd be inserting new entries into the symbol table dynamically.</p>
  
  <p>What is the Haskell equivilent of this idiom?</p>
  
  <p><em>Btw, I'm fully aware that I'm duplicating the work of many existing libraries that already do HTML tags. I'm doing this for a toy project, nothing more :)</em></p>
  
  <p>EDIT: Some posted solutions are suggesting mechanisms that still rely on defining the <em>end result</em> tag functions one-by-one. This violates DRY, else I would have just done it how I was doing it. It's that DRY violation that I'm trying to side-step.</p>