title: polymorphic function on existential type
body: <p>So say I have a class:</p>
  
  <pre><code>class C a where
    reduce :: a -&gt; Int
  </code></pre>
  
  <p>Now I want to pack it up in a data type:</p>
  
  <pre><code>data Signal = forall a. (C a) =&gt; Signal [(Double, a)]
  </code></pre>
  
  <p>Thanks to the existential quantification, I can call C methods on Signals, but Signals don't expose a type parameter:</p>
  
  <pre><code>reduceSig :: Signal -&gt; [(Double, Int)]
  reduceSig (Signal sig) = map (second reduce) sig
  </code></pre>
  
  <p>Now since C has a number of methods my natural next step is to pull out the 'reduce' function so I can substitute any method:</p>
  
  <pre><code>mapsig :: (C a) =&gt; (a -&gt; a) -&gt; Signal -&gt; Signal
  mapsig f (Signal sig) = Signal (map (second f) sig)
  </code></pre>
  
  <p>Type error!  Could not deduce (a1 ~ a).  On further thought, I think what it's saying is that 'f' is a function on some instance of C, but I can't guarantee it's the <em>same</em> instance of C as in the Signals, because the type parameters are concealed!  I wanted it, I got it.</p>
  
  <p>So does this mean it's impossible to generalize reduceSig?  I can live with this, but I'm so used to freely factoring out functions in haskell it feels strange to be obliged to write the boilerplate.  On the other hand, I can't think of any way to express that a type is equal to the type inside of Signal, short of giving Signal a type parameter.</p>