title: What to do with “Inferred type is less polymorphic than expected”?
body: <p>I need the Numeric.FAD library, albeit still being completely puzzled by existential types.</p>
  
  <p>This is the code:</p>
  
  <pre><code>error_diffs :: [Double] -&gt; NetworkState [(Int, Int, Double)]
  error_diffs desired_outputs = do diff_error &lt;- (diff_op $ error' $ map FAD.lift desired_outputs)::(NetworkState ([FAD.Dual tag Double] -&gt; FAD.Dual tag Double))
                                   weights &lt;- link_weights
                                   let diffs = FAD.grad (diff_error::([FAD.Dual tag a] -&gt; FAD.Dual tag b)) weights
  
                                   links &lt;- link_list
                                   return $ zipWith (\link diff -&gt;
                                                         (linkFrom link, linkTo link, diff)
                                                    ) links diffs
  </code></pre>
  
  <p>error' runs in a Reader monad, ran by diff_op, which in turn generates an anonymous function to take the current NetworkState and the differential inputs from FAD.grad and stuffs them into the Reader.</p>
  
  <p>Haskell confuses me with the following:</p>
  
  <pre><code>Inferred type is less polymorphic than expected
    Quantified type variable `tag' is mentioned in the environment:
      diff_error :: [FAD.Dual tag Double] -&gt; FAD.Dual tag Double
        (bound at Operations.hs:100:33)
  In the first argument of `FAD.grad', namely
      `(diff_error :: [FAD.Dual tag a] -&gt; FAD.Dual tag b)'
  In the expression:
      FAD.grad (diff_error :: [FAD.Dual tag a] -&gt; FAD.Dual tag b) weights
  In the definition of `diffs':
      diffs = FAD.grad
                (diff_error :: [FAD.Dual tag a] -&gt; FAD.Dual tag b) weights
  </code></pre>