title: Count negative numbers in list using list comprehension
body: <p>Working through the first edition of "Introduction to Functional Programming", by Bird &amp; Wadler, which uses a theoretical lazy language with Haskell-ish syntax.</p>
  
  <p>Exercise 3.2.3 asks:</p>
  
  <blockquote>
    <p>Using a list comprehension, define a function for counting the number
    of negative numbers in a list</p>
  </blockquote>
  
  <p>Now, at this point we're still scratching the surface of lists. I would assume the intention is that only concepts that have been introduced at that point should be used, and the following have <strong>not</strong> been introduced yet:</p>
  
  <ul>
  <li>A function for computing list length</li>
  <li>List indexing</li>
  <li>Pattern matching i.e. f (x:xs) = ...</li>
  <li>Infinite lists</li>
  <li>All the functions and operators that act on lists - with one exception - e.g. ++, head, tail, map, filter, zip, foldr, etc</li>
  </ul>
  
  <p>What tools are available?</p>
  
  <ul>
  <li>A maximum function that returns the maximal element of a numeric list</li>
  <li>List comprehensions, with possibly multiple generator expressions and predicates</li>
  <li>The notion that the output of the comprehension need not depend on the generator expression, implying the generator expression can be used for controlling the size of the generated list</li>
  <li>Finite arithmetic sequence lists i.e. [a..b] or [a, a + step..b]</li>
  </ul>
  
  <p>I'll admit, I'm stumped. Obviously one can extract the negative numbers from the original list fairly easily with a comprehension, but how does one then count them, with no notion of length or indexing?</p>
  
  <p>The availability of the maximum function would suggest the end game is to construct a list whose maximal element is the number of negative numbers, with the final result of the function being the application of maximum to said list.</p>
  
  <p>I'm either missing something blindingly obvious, or a smart trick, with a horrible feeling it may be the former. Tell me SO, how do you solve this?</p>