title: Demangling typeclass functions in GHC profiler output
body: <p>When profiling a Haskell program written in GHC, the names of typeclass functions are mangled in the .prof file to distinguish one instance's implementations of them from another.  How can I demangle these names to find out which type's instance it is?</p>
  
  <p>For example, suppose I have the following program, where types <code>Fast</code> and <code>Slow</code> both implement <code>Show</code>:</p>
  
  <pre><code>import Data.List (foldl')
  
  sum' = foldl' (+) 0
  
  data Fast = Fast
  instance Show Fast where
      show _ = show $ sum' [1 .. 10]
  
  data Slow = Slow
  instance Show Slow where
      show _ = show $ sum' [1 .. 100000000]
  
  main = putStrLn (show Fast ++ show Slow)
  </code></pre>
  
  <p>I compile with <code>-prof -auto-all -caf-all</code> and run with <code>+RTS -p</code>.  In the .prof file that gets generated, I see that the top cost centers are:</p>
  
  <pre><code>COST CENTRE                    MODULE               %time %alloc
  
  show_an9                       Main                  71.0   83.3
  sum'                           Main                  29.0   16.7
  </code></pre>
  
  <p>And in the tree, I likewise see (omitting irrelevant lines):</p>
  
  <pre><code>                                                individual    inherited
  COST CENTRE       MODULE       no.    entries  %time %alloc   %time %alloc
  
    main            Main         232           1   0.0    0.0   100.0  100.0
     show_an9       Main         235           1  71.0   83.3   100.0  100.0
      sum'          Main         236           0  29.0   16.7    29.0   16.7
     show_anx       Main         233           1   0.0    0.0     0.0    0.0
  </code></pre>
  
  <p>How do I figure out that <code>show_an9</code> is <code>Slow</code>'s implementation of <code>show</code> and not <code>Fast</code>'s?</p>