title: In Scala, when is it necessary to specify laziness?
body: <p>In the local Scala REPL, one can define streams and lazy lists without the keyword <code>lazy</code>.</p>
  
  <pre><code>scala&gt; val fibo: LazyList[BigInt] = (0: BigInt) #:: (1: BigInt) #:: fibo.zip(fibo.tail).map { n =&gt; n._1 + n._2 }
  fibo: LazyList[BigInt] = LazyList(&lt;not computed&gt;)
  
  scala&gt; fibo(100)
  res17: BigInt = 354224848179261915075
  
  scala&gt; val prime: LazyList[Int] = 2 #:: LazyList.from(3).filter(i =&gt; prime.takeWhile {
       |    j =&gt; j * j &lt;= i
       | }.forall {
       |    k =&gt; i % k != 0
       | })
  prime: LazyList[Int] = LazyList(&lt;not computed&gt;)
  
  scala&gt; prime(100)
  res18: Int = 547
  </code></pre>
  
  <p>This would work much the same way with <code>Stream</code>, and also in Scastie. It should also work in an IntelliJ project, right?</p>
  
  <pre><code>  @Test def testGCDConsecutivePrimeNumbers(): Unit = {
      val prime: LazyList[Int] = 2 #:: LazyList.from(3).filter(i =&gt; prime.takeWhile {
        j =&gt; j * j &lt;= i
      }.forall {
        k =&gt; i % k != 0
      })
      for (n &lt;- 1 to 100) {
        assertEquals(1, gcd(prime(n), prime(n + 1)))
      }
    }
  
    @Test def testGCDConsecutiveEvenFibonacciNumbers(): Unit = {
      val fibo: LazyList[Int] = 0 #:: 1 #:: fibo.zip(fibo.tail).map(n =&gt; n._1 + n._2)
      for (i &lt;- 0 to 42 by 3) {
        assertEquals(2, gcd(fibo(i), fibo(i + 3)))
      }
    }
  </code></pre>
  
  <p>Except it doesn't.</p>
  
  <blockquote>
    <p>Error:(21, 67) forward reference extends over definition of value <code>prime</code></p>
    
    <p><code>val prime: LazyList[Int] = 2 #:: LazyList.from(3).filter(i =&gt; prime.takeWhile {</code></p>
    
    <p>Error:(32, 43) forward reference extends over definition of value <code>fibo</code></p>
    
    <p><code>val fibo: LazyList[Int] = 0 #:: 1 #:: fibo.zip(fibo.tail).map(n =&gt; n._1 + n._2)</code></p>
  </blockquote>
  
  <p>Marking them lazy clears the errors.</p>
  
  <p>I understand some things work differently in the REPL, but I don't understand why this would be one of those things. And I'm probably missing some subtlety here, but why doesn't omitting "<code>lazy</code>" in the REPL cause a forward reference error. In general, when is it necessary to explicitly specify laziness, and why?</p>