title: Less-than function in Standard ML
body: <p>I'm trying to make a function in SML that takes a list and an int and returns a list of all elements that are less than the int <code>int * int list -&gt; int list</code> I wrote the following code:</p>
  
  <pre><code>- fun less (e, L) = 
  =   map (fn a =&gt; if a &lt; e then a else []) L;
  </code></pre>
  
  <p>also with the following code it doesnt work also:</p>
  
  <pre><code>- fun less (e, L) = 
  =   map (fn a =&gt; if a &lt; e then a) L;
  </code></pre>
  
  <p>and the error im getting is :</p>
  
  <pre><code>stdIn:22.15-22.38 Error: types of if branches do not agree [overload]
    then branch: 'Z
    else branch: 'Y list
    in expression:
      if a &lt; e then a else nil
  </code></pre>
  
  <p>I think the problem is with the else part but I dont know what to put in it to work, anybody have any suggestion? I should use either map, foldl, or foldr functions.</p>
  
  <p>EDIT:</p>
  
  <pre><code>- fun less (e, L) = 
  =   let
  =       val acc = []
  =   in
  =       foldr (fn a =&gt; if a &lt; e then a::acc else acc) acc L
  =   end;
  </code></pre>
  
  <p>still gives me error, the following error : </p>
  
  <pre><code>stdIn:241.3-241.54 Error: operator and operand don't agree [overload]
    operator domain: 'Z * 'Y -&gt; 'Y
    operand:         'X -&gt; 'X list
    in expression:
      foldr (fn a =&gt; if &lt;exp&gt; &lt; &lt;exp&gt; then &lt;exp&gt; :: &lt;exp&gt; else acc)
  </code></pre>