title: Haskell introspecting a record's field names and types
body: <p>Based on a <a href="https://stackoverflow.com/questions/8659939/haskell-setting-record-field-based-on-field-name-string">recent exchange</a>, I've been convinced to use Template Haskell to generate some code to ensure compile-time type safety.</p>
  
  <p>I need to introspect record field names and types. I understand I can <a href="https://stackoverflow.com/questions/8457876/get-a-haskell-records-field-names-as-a-list-of-strings">get field names</a> by using <code>constrFields . toConstr :: Data a =&gt; a -&gt; [String]</code>. But I need more than the field names, I need to know their type. For example, I need to know the names of fields that are of type <code>Bool</code>.</p>
  
  <p>How do I construct a function <code>f :: a -&gt; [(String, xx)]</code> where <code>a</code> is the record, <code>String</code> is the field name and <code>xx</code> is the field type?</p>