title: Getting associated type synonyms with template Haskell
body: <p>Can Template Haskell find out the names and/or the declarations of the associated type synonyms declared in a type class?  I expected <a href="http://hackage.haskell.org/packages/archive/template-haskell/latest/doc/html/Language-Haskell-TH.html#v:reify"><code>reify</code></a> would do what I want, but it doesn't seem to provide all the necessary information.  It works for getting function type signatures:</p>
  
  <pre><code>% ghci
  GHCi, version 7.8.3: http://www.haskell.org/ghc/  :? for help
  ...
  Prelude&gt; -- I'll be inserting line breaks and whitespace for clarity
  Prelude&gt; -- in all GHCi output.
  Prelude&gt; :set -XTemplateHaskell 
  Prelude&gt; import Language.Haskell.TH
  Prelude Language.Haskell.TH&gt; class C a where f :: a -&gt; Int
  Prelude Language.Haskell.TH&gt; putStrLn $(stringE . show =&lt;&lt; reify ''C)
  ClassI (ClassD [] Ghci1.C [PlainTV a_1627398388] []
                 [SigD Ghci1.f
                       (ForallT [PlainTV a_1627398388]
                                [ClassP Ghci1.C [VarT a_1627398388]]
                                (AppT (AppT ArrowT (VarT a_1627398388))
                                      (ConT GHC.Types.Int)))])
         []
  </code></pre>
  
  <p>However, adding an associated type synonym to the class causes no change (up to renaming) in the output:</p>
  
  <pre><code>Prelude Language.Haskell.TH&gt; :set -XTypeFamilies 
  Prelude Language.Haskell.TH&gt; class C' a where type F a :: * ; f' :: a -&gt; Int
  Prelude Language.Haskell.TH&gt; putStrLn $(stringE . show =&lt;&lt; reify ''C')
  ClassI (ClassD [] Ghci3.C' [PlainTV a_1627405973] []
                 [SigD Ghci3.f'
                       (ForallT [PlainTV a_1627405973]
                                [ClassP Ghci3.C' [VarT a_1627405973]]
                                (AppT (AppT ArrowT (VarT a_1627405973))
                                      (ConT GHC.Types.Int)))])
         []
  </code></pre>
  
  <p>If I know the name of <code>F</code>, I can look up information about it:</p>
  
  <pre><code>Prelude Language.Haskell.TH&gt; putStrLn $(stringE . show =&lt;&lt; reify ''F)
  FamilyI (FamilyD TypeFam
                   Ghci3.F
                   [PlainTV a_1627405973]
                   (Just StarT))
          []
  </code></pre>
  
  <p>But I can't find the name of <code>F</code> in the first place.  Even if I add an instance of the type class, the <code>InstanceD</code> has none of the information about the definition:</p>
  
  <pre><code>Prelude Language.Haskell.TH&gt; instance C' [a] where type F [a] = a ; f' = length
  Prelude Language.Haskell.TH&gt; f' "Haskell"
  7
  Prelude Language.Haskell.TH&gt; 42 :: F [Integer]
  42
  Prelude Language.Haskell.TH&gt; putStrLn $(stringE . show =&lt;&lt; reify ''C')
  ClassI (ClassD [] Ghci3.C' [PlainTV a_1627405973] []
                 [SigD Ghci3.f'
                       (ForallT [PlainTV a_1627405973]
                                [ClassP Ghci3.C' [VarT a_1627405973]]
                                (AppT (AppT ArrowT (VarT a_1627405973))
                                      (ConT GHC.Types.Int)))])
         [InstanceD []
                    (AppT (ConT Ghci3.C')
                          (AppT ListT (VarT a_1627406161)))
                    []]
  </code></pre>
  
  <p>If <code>reify</code> won't work, is there a workaround, other than listing the associate type synonyms manually?</p>
  
  <p>This problem is present in GHC 7.8.3 with version 2.9.0.0 of the template-haskell package; it was also present in GHC 7.4.2 with version 2.7.0.0 of the template-haskell package.  (I didn't check on GHC 7.6.*, but I imagine it was present there too.)  I'm interested in solutions for any version of GHC (including "this was only fixed in GHC version <em>V</em>").</p>