Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A list comprehension is guaranteed to look at every element of the list. You want <a href="http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v%3atakeWhile" rel="nofollow"><code>takeWhile :: (a -&gt; Bool) -&gt; [a] -&gt; [a]</code></a>. With it, your list is simply <code>takeWhile (&lt; 1000000) $ map fib [1..]</code>. The <code>takeWhile</code> function simply returns the leading portion of the list which satisfies the given predicate; there's also a similar <a href="http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v%3adropWhile" rel="nofollow"><code>dropWhile</code></a> function which drops the leading portion of the list which satisfies the given predicate, as well as <a href="http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v%3aspan" rel="nofollow"><code>span :: (a -&gt; Bool) -&gt; [a] -&gt; ([a], [a])</code></a>, which is just <code>(takeWhile p xs, dropWhile p xs)</code>, and the similar <a href="http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v%3abreak" rel="nofollow"><code>break</code></a>, which breaks the list in two when the predicate is true (and is equivalent to <code>span (not . p)</code>. Thus, for instance:</p> <ul> <li><code>takeWhile (&lt; 3) [1,2,3,4,5,4,3,2,1] == [1,2]</code></li> <li><code>dropWhile (&lt; 3) [1,2,3,4,5,4,3,2,1] == [3,4,5,4,3,2,1]</code></li> <li><code>span (&lt; 3) [1,2,3,4,5,4,3,2,1] == ([1,2],[3,4,5,4,3,2,1])</code></li> <li><code>break (&gt; 3) [1,2,3,4,5,4,3,2,1] == ([1,2,3],[4,5,4,3,2,1])</code></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload