Why is it possible to assign recursive lambdas to non-lazy vals in Scala?
In the following statement the val f is defined as a lambda that references itself (it is recursive): val f: Int => Int = (a: Int) => if (a > 10) 3 else f(a + 1) + 1 // just some simple function I've tried it in the REPL, and it compiles and executes correctly. According to the specification, this seems like an instance of illegal forward referencing: In a statement sequence s[1]...s[n] making up a block, if a simple name in s[i] refers to an entity defined by s[j] where j >= i , then for all s[k] between and including s[i] and s[j] , s[k] cannot be a variable definition. If s[k] is a value