title: How to do an addition on a list with a condition?
body: <p>I have a university course about functional programming, where I use SML. As a preparation for the exam, I am working on some of the older exam sets without solutions.</p>
  <p>One of the only questions I really have problems with is the following question using <code>foldl</code>:</p>
  <blockquote>
  <p>Consider the program skeleton: fun
  addGt k xs = List.foldl (...) ... xs;
  Fill in the two missing pieces
  (represented by the dots ...), so that
  addGt k xs is the sum of those
  elements in xs, which are greater than
  k. For example, addGt 4 [1, 5, 2, 7,
  4, 8] = 5 + 7 + 8 = 20</p>
  </blockquote>
  <p>I am sure this is really easy, but I have a very hard time understanding the foldl and foldr functions.</p>
  <p>What I have now is the following (which seems to be very wrong if you ask my compiler!):</p>
  <pre><code>fun addGt(k,xs) = List.foldl ( fn x =&gt; if x &gt; k then op+ else 0) 0 xs;
  </code></pre>
  <p>I would really appreciate some help with this question, and maybe a very short comment which would cast some light on the <code>foldl</code> and <code>foldr</code> functions!</p>