[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Should the car be a stream?
This page is part of the web mail archives of SRFI 41 from before July 7th, 2015. The new archives for SRFI 41 contain all messages, not just those from before July 7th, 2015.
- To: "David Van Horn" <dvanhorn@xxxxxxxxxxxxxxx>, srfi-41@xxxxxxxxxxxxxxxxx
- Subject: Re: Should the car be a stream?
- From: "Phil Bewig" <pbewig@xxxxxxxxx>
- Date: Wed, 14 Nov 2007 19:48:42 -0600
- Delivered-to: srfi-41@xxxxxxxxxxxxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; bh=BoHuNpsBemaXr1UeUJPOJp5Ce2dFLEjSM0e6rGDzexQ=; b=bcY8R/s6pe1OP0oUxftWyizaQKhkUnul+dc/mFIOFUYOJKscy++j/SHLBuWulsMY5vBcnLL+H3AYqQ+x7n5P8qWdL+l21c7BFAPaBMDUJbxwrVCJ6GOc+hJ3oaP3tIfNN02cXxbJzLIXyj9EMwxOlG7TINWWWYVCOtpue3acgjk=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=ZDYEmp4rLu7xi56EmEnQmo0w1k98/dT2vDHJR3A1644wbqo0LvhyM6NLiCvUlWpgDd/+E8G03mTAYyWITFBWroByZyl4iwNnZmdzTkLdL3lmMR7GAhbwCnh0vCzB+j4MMkdF47ltb2VCJJnXEh/qzEXaqD7lTZidvrzK1f3IB7c=
- In-reply-to: <473B9804.1070608@xxxxxxxxxxxxxxx>
- References: <Pine.SOC.4.64.0711141826090.20861@xxxxxxxxxxxxxxxxx> <473B9804.1070608@xxxxxxxxxxxxxxx>
I think I am saying (eq? stream-type promise-type) is #t and Andre is saying (eqv? stream-type promise-type) is #f. Both statements are correct. Since both stream-type and promise-type are abstract, I can mix them up inside (streams primitive) without consequence, except that it causes some confusion. I guess it is more precise to say that the type of the stream-car is a promise, not a stream, except that in the implementation they are the same thing. Andre is correct in that I could have implemented the car of a stream as an ordinary promise instead of a stream-promise.
Types of the primitive functions aren't very interesting:
stream? :: alpha -> boolean
stream-pair? :: alpha -> boolean
stream-null? :: alpha -> boolean
stream-car :: alpha stream -> alpha
stream-cdr :: alpha stream -> alpha stream
Stream-null, stream-cons and stream-lambda are all syntax and have no type. I guess you could say that the type of stream-null is alpha stream and the type of stream-cons is alpha * alpha-stream -> alpha stream. I don't know how to writhe the type of stream-lambda.
On Nov 14, 2007 6:51 PM, David Van Horn <dvanhorn@xxxxxxxxxxxxxxx
AndrevanTonder wrote:I agree, from the types given, this doesn't seem right.
> The following seems wrongly typed to me:
> (define-syntax stream-cons
> (syntax-rules ()
> ((stream-cons obj strm)
> (stream-delay (make-stream-pare
> (stream-delay obj) ;???
> (stream-lazy strm))))))
> Specifically, I don't think the car of a stream should be a stream.
Why weren't there types given for the streams primitives library? This
seems like a valuable part of the spec to me.
If the elements were not themselves delayed by default, computing the
> But even I am wondering about the rationale for making the stream
> elements themselves promises. It may be useful to leave the types of
> the elements (including whether they are promises or ordinary values)
> orthogonal to the backbone of the stream itself.
> I suspect that if the elements were not themselves delayed by default,
> you would see a huge difference in performance.
nth element of a stream is proportional to computing each element
previous to it. In the lazy version, it's simply proportional to n.
It's easy to imagine cases that perform infinitely worse using the first
model compared to the second.
To me at least, it's important that no element of a lazy list is
evaluated until it is needed. This is what SRFI 40 specifies in prose
"no element of the stream is evaluated until it is accessed," but the
code does otherwise. I'm glad to see SRFI 41 fix the problem.