title: Haskell list comprehension for finding primes
body: <p>I'm trying to find all the primes less than some integer <code>n</code> as concisely as possible, using list comprehensions. I'm learning Haskell, and this is just an exercise. I'd like to write something like:</p>
  
  <pre><code>isqrt :: Integral a =&gt; a -&gt; a   
  isqrt = floor . sqrt . fromIntegral
  
  primes :: Integral a =&gt; a -&gt; [a]  
  primes n = [i | i &lt;- [1,3..n], mod i k /= 0 | k &lt;- primes (isqrt i)]
  </code></pre>
  
  <p>which of course doesn't work. Is there a way to have a list comprehension inside a list comprehension?</p>
  
  <p>Here is the error I'm getting:</p>
  
  <pre><code>exercise-99-1.hs:138:39: Not in scope: `k'
  
  exercise-99-1.hs:138:46:
      Illegal parallel list comprehension: use -XParallelListComp
  
  exercise-99-1.hs:138:68: Not in scope: `i'
  </code></pre>
  
  <p>BUT - I wasn't really expecting the syntax to even be legit :-)</p>
  
  <p>The intent was to translate as directly as possible: <em>" <code>primes n</code> = the set of odd integers <code>i</code> less than <code>n</code> such that <code>i</code> is not divisible by any <code>k</code>, for all <code>k</code> in the set: <code>primes (isqrt i)</code>"</em> - more or less. (I hope I got that right?)</p>
  
  <p>Thanks!</p>