title: Error on matching the type signature on function for a list of pairs
body: <p>I am trying to write a function that takes a list of pairs, ex. [(1,2),(1,4),(2,5),(3,4),(1,8)] and it returns the list of the sum of the second values of each pair, for each of first value in a sorted manner. ex.[14,5,4].</p>
  <p>To do this I made a comprehension list to fold the second values from a list of pairs, and a comprehension list where the list of pairs is filtered by the first value.</p>
  <pre><code>addSec :: (Num a, Num b) =&gt; [(a,b)] -&gt; b
  addSec a = foldr (+) 0 (map snd a)
  
  listf ::(Num a,Enum a,Eq a,Fractional a,RealFrac a)=&gt; a -&gt;[a]
  listf g =  [ a | x &lt;- [0..g], a &lt;- addSec(filter ((== x ).fst) z ) ] 
                          where
                          z=[ (x,y) | x &lt;-reverse [1..553],                                               
                                    let s = x * (fromIntegral (ceiling(504 / x))) - 504,  
                                     y &lt;- [s..g] ] 
  
  </code></pre>
  <p>I have tried the functions</p>
  <pre><code>foldr (+) 0 (map snd a) 
  
  filter ((== x ).fst) z
  </code></pre>
  <p>separately on <code>Prelude&gt;</code> and they work as intended but I get this sort of error in a program:</p>
  <pre><code>
  try.hs:20:36: error:
      * Occurs check: cannot construct the infinite type: a ~ [a]
      * In the expression: addSec (filter ((== x) . fst) z)
        In a stmt of a list comprehension:
          a &lt;- addSec (filter ((== x) . fst) z)
        In the expression:
          [a | x &lt;- [0 .. g], a &lt;- addSec (filter ((== x) . fst) z)]
      * Relevant bindings include
          x :: a (bound at try.hs:20:18)
          z :: [(a, a)] (bound at try.hs:22:25)
          g :: a (bound at try.hs:20:7)
          listf :: a -&gt; [a] (bound at try.hs:20:1)
     |
  20 | listf g =  [ a | x &lt;- [0..g], a &lt;- addSec(filter ((== x ).fst) z ) ]
     |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  Failed, no modules loaded.
  </code></pre>
  <p>I get similar errors even when the type signature is:</p>
  <pre><code>addSec :: [(a,b)] -&gt; a
  </code></pre>
  <p>So I am not sure what to change. Thank you very much, I appreciate any help.</p>