1
Stream
개의 정사각형을 갖고 싶다고합시다. 간단한 방법은 될 것이라고 선언합니다 :스칼라 컴파일러가 스트림 유형 연산을 유추하지 못하는 이유는 무엇입니까?
<console>:8: error: overloaded method value * with alternatives:
(x: Double)Double <and>
(x: Float)Float <and>
(x: Long)Long <and>
(x: Int)Int <and>
(x: Char)Int <and>
(x: Short)Int <and>
(x: Byte)Int
cannot be applied to (scala.collection.immutable.Stream[Int])
def squares(n: Int): Stream[Int] = n * n #:: squares(n + 1)
^
그래서, 왜 스칼라가 분명히 Int
입니다 n
의 유형을 추론 할 수 없습니다
scala> def squares(n: Int): Stream[Int] = n * n #:: squares(n + 1)
그러나 이렇게 오류를 얻을? 누군가가 무슨 일이 일어나는지 설명해 주시겠습니까?