logo       

Scala's "odd" streams: msg#00074

lang.scala

Subject: Scala's "odd" streams

In "How to add laziness to a strict language without even being odd",
Wadler, Taha and MacQueen categorized the type of streams that Scala
implements as "odd" for two reasons:
1. Odd number of constructors (cons, delay, null)
2. Off-by-one error in methods defined on streams such as take

I posted a test program at the bug database (bug #111):
http://lamppc1s1.epfl.ch/bugtracking/contribs/display.do?id=111

Because the stream's head is eagerly evaluated, the square root of -1
is computed; in Scala this would just silently fail but a function
call on an invalid argument could potentially throw an exception here,
and that would be undesirable.

My question is, what's the best way to fix this? Would making the head
of the stream also call-by-name result in much of a performance hit?
Or would a less intrusive solution like the one I posted be better?
(Just avoid ever taking the tail if its head is never going to be
returned; in case of take(n), stop when n==1)

Best regards,

--
Michel Salim
http://www.cs.indiana.edu/~msalim



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise